Commit 9c31655a authored by 黄奎's avatar 黄奎

页面修改

parent fb5f91ea
......@@ -29,7 +29,8 @@ namespace EduSpider.Utility
SslProtocols = System.Security.Authentication.SslProtocols.Tls
};
var http = new HttpClient(handler);
GenerateHttpHeader(ref http);
//GenerateHttpHeader(ref http);
FirefoxHttpHeader(ref http);
return http;
}
......@@ -63,6 +64,24 @@ namespace EduSpider.Utility
http.DefaultRequestHeaders.Add("pragma", "no-cache");
}
/// <summary>
/// 火狐Http请求
/// </summary>
/// <param name="http"></param>
private static void FirefoxHttpHeader(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.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
http.DefaultRequestHeaders.Add("Origin", "https://console.eeo.cn");
http.DefaultRequestHeaders.Add("Referer", "https://console.eeo.cn/saas/school/index.html");
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("TE", "trailers");
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0");
}
/// <summary>
/// 拼接Cookie
/// </summary>
......
using System;
using System.IO;
using System.Threading.Tasks;
namespace EduSpider.Utility.Plugin
{
/// <summary>
/// 日志帮助类
/// </summary>
public class LogHelper
{
private static readonly string logDir = Config.LogPath;
private static readonly string infoLogDir = Config.InofLogPath;
private static readonly string requestLogDir = Config.RequestLogPath;
private static readonly object objError = new object();
private static readonly object objInfo = new object();
private static readonly object objRequest = new object();
/// <summary>
/// 构造函数
/// </summary>
static LogHelper()
{
if (!Directory.Exists(logDir))
Directory.CreateDirectory(logDir);
if (!Directory.Exists(infoLogDir))
Directory.CreateDirectory(infoLogDir);
if (!Directory.Exists(requestLogDir))
Directory.CreateDirectory(requestLogDir);
}
/// <summary>
/// 写日志(异常日志)
/// </summary>
/// <param name="ex">异常内容</param>
public static void Write(Exception ex)
{
Write(ex, "");
}
/// <summary>
/// 写日志(异常日志)
/// </summary>
/// <param name="msg">信息</param>
public static void Write(string msg)
{
Write(null, msg);
}
/// <summary>
/// 写日志(异常日志)
/// </summary>
/// <param name="exception">异常信息</param>
/// <param name="otherMsg">其他信息</param>
public static void Write(Exception exception, string otherMsg)
{
Task.Run(() => WriteLog(exception, otherMsg, LogEnum.Error));
}
/// <summary>
/// 打印信息(记录信息)
/// </summary>
/// <param name="msg">信息</param>
public static void WriteInfo(string msg)
{
Task.Run(() => WriteLog(null, msg, LogEnum.Info));
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="exception">异常信息</param>
/// <param name="otherMsg">其他信息</param>
/// <param name="logType">日志类型</param>
private static void WriteLog(Exception exception, string otherMsg, LogEnum logType)
{
string str = "";
try
{
str += string.Format(@"
DateTime:{0}", DateTime.Now.ToString());
if (exception != null)
{
if (exception.InnerException != null)
{
exception = exception.InnerException;
}
str += string.Format(@"
Message:{0}
StackTrace:
{1}
Source:{2}
"
, exception.Message
, exception.StackTrace
, exception.Source
);
}
str += string.Format(@"
ExtMessage:{0}", otherMsg);
string filePath = "";
object lockObj = new object();
switch (logType)
{
case LogEnum.Error:
filePath = Path.Combine(logDir, DateTime.Now.ToString("yyyyMMdd") + ".txt");
lockObj = objError;
break;
case LogEnum.Info:
filePath = Path.Combine(infoLogDir, DateTime.Now.ToString("yyyyMMdd") + ".txt");
lockObj = objInfo;
break;
case LogEnum.Request:
filePath = Path.Combine(requestLogDir, DateTime.Now.ToString("yyyyMMdd") + ".txt");
lockObj = objRequest;
break;
}
lock (lockObj)
{
StreamWriter sw = new StreamWriter(filePath, true);
sw.WriteLine(str);
sw.Close();
}
}
catch
{
}
}
}
/// <summary>
/// 日志枚举
/// </summary>
public enum LogEnum
{
/// <summary>
/// 错误日志
/// </summary>
Error = 1,
/// <summary>
/// 信息记录
/// </summary>
Info = 2,
/// <summary>
/// 接口请求
/// </summary>
Request = 3
}
}
......@@ -36,7 +36,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="OpenCvSharp4.Windows" Version="4.5.5.20211231" />
<PackageReference Include="Selenium.WebDriver" Version="4.1.0" />
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="102.0.5005.6102" />
<PackageReference Include="Selenium.WebDriver.GeckoDriver" Version="0.31.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
......
......@@ -30,11 +30,10 @@ namespace EduSpider.Spiders.ClassInRule
string paramStr = string.Format("page={0}&perpage={1}", pageIndex, perpage);
var content = new StringContent(paramStr, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
var response = await request.PostAsync("https://console.eeo.cn/saasajax/teacher.ajax.php?action=getSchoolTeacherFullList", content);
var result = response.Content.ReadAsStringAsync().Result;
if (!string.IsNullOrWhiteSpace(result))
{
VTX.FW.Helper.LogHelper.WriteInfo("RunTeacher", $"result: {result}");
JObject rootObj = JObject.Parse(result);
if (!string.IsNullOrWhiteSpace(rootObj.GetString("data")))
{
......
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