Commit 1220ce85 authored by 罗超's avatar 罗超

新增学员获取

parent c8f33476
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using TicketSpider.Spiders.ClassInRule;
namespace EduSpider.Helpers
{
public class HttpHelper
{
public static HttpClient GenerateHttp()
{
var handler = new HttpClientHandler();
handler.AllowAutoRedirect = false;
handler.UseCookies = true;
handler.CookieContainer = CreateCookie();
handler.AutomaticDecompression = DecompressionMethods.GZip;
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;
var http = new HttpClient(handler);
GenerateHttpHeader(ref http);
return http;
}
private static void GenerateHttpHeader(ref HttpClient http)
{
http.DefaultRequestHeaders.Add("Accept", "application/json, text/plain, */*");
http.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br");
http.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.9,ja;q=0.8");
http.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
http.DefaultRequestHeaders.Add("Origin", "https://console.eeo.cn");
http.DefaultRequestHeaders.Add("Pragma", "no-cache");
http.DefaultRequestHeaders.Add("Referer", "https://console.eeo.cn/saas/school/index.html");
http.DefaultRequestHeaders.Add("salesChannel", "NzcwMQ==");
http.DefaultRequestHeaders.Add("sec-ch-ua", "\" Not; A Brand\";v=\"99\", \"Google Chrome\";v=\"97\", \"Chromium\";v=\"97\"");
http.DefaultRequestHeaders.Add("sec-ch-ua-mobile", "?0");
http.DefaultRequestHeaders.Add("sec-ch-ua-platform", "\"Windows\"");
http.DefaultRequestHeaders.Add("Sec-Fetch-Dest", "empty");
http.DefaultRequestHeaders.Add("Sec-Fetch-Mode", "cors");
http.DefaultRequestHeaders.Add("Sec-Fetch-Site", "same-origin");
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36");
http.DefaultRequestHeaders.Add("site", "zh_CN");
http.DefaultRequestHeaders.Add("shakehand", "535206fb27efbaf75066ff179b975ff6");
http.DefaultRequestHeaders.Add("pragma", "no-cache");
}
private static CookieContainer CreateCookie()
{
var cookieStr = ClassInAccountManager.GetInstance();
var uri = new Uri("https://console.eeo.cn");
var cc = new CookieContainer();
foreach (var str in cookieStr.Split(';'))
{
cc.SetCookies(uri, str);
}
return cc;
}
}
}
......@@ -45,7 +45,7 @@ namespace TicketSpider.Spiders.ClassInRule
{
cnt++;
var result = RunAsync();
if (result)
if (result && !_openHeartTimer)
{
_openHeartTimer = true;
Task.Run(() => HeartLine());
......@@ -72,7 +72,7 @@ namespace TicketSpider.Spiders.ClassInRule
IWebElement pwdEle = null;
var option = new ChromeOptions();
option.AddArgument("--incognito");
//option.AddArgument("headless");
option.AddArgument("headless");
option.AddArgument("disable-infobars");
option.AddArgument("window-size=1920,1080");
option.AddArgument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36");
......
using Newtonsoft.Json.Linq;
using EduSpider.Spiders.ClassInRule;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
......@@ -19,6 +20,8 @@ namespace TicketSpider.Spiders.ClassInRule
{
Console.WriteLine("开始模拟登录信息.......");
string loginCookies = ClassInAccountManager.GetInstance();
Console.WriteLine("开始获取学员信息");
new StudentManager().RunAsync();
}
......
using EduSpider.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace EduSpider.Spiders.ClassInRule
{
public class StudentManager
{
public async void RunAsync()
{
var request = HttpHelper.GenerateHttp();
var paramStr = "page=1&perpage=20&isdel=0";
var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await request.PostAsync("https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage", content);
var result = response.Content.ReadAsStringAsync().Result;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment