Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EduSpider
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
viitto
EduSpider
Commits
9c31655a
Commit
9c31655a
authored
Sep 06, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
fb5f91ea
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
305 additions
and
20 deletions
+305
-20
HttpHelper.cs
EduSpider.Utility/HttpHelper.cs
+20
-1
LogHelper.cs
EduSpider.Utility/Plugin/LogHelper.cs
+152
-0
EduSpider.csproj
EduSpider/EduSpider.csproj
+1
-1
ClassInAccountManager.cs
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
+131
-16
TeacherManager.cs
EduSpider/Spiders/ClassInRule/TeacherManager.cs
+1
-2
No files found.
EduSpider.Utility/HttpHelper.cs
View file @
9c31655a
...
...
@@ -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>
...
...
EduSpider.Utility/Plugin/LogHelper.cs
0 → 100644
View file @
9c31655a
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
}
}
EduSpider/EduSpider.csproj
View file @
9c31655a
...
...
@@ -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" />
...
...
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
View file @
9c31655a
This diff is collapsed.
Click to expand it.
EduSpider/Spiders/ClassInRule/TeacherManager.cs
View file @
9c31655a
...
...
@@ -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"
)))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment