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
703a941d
Commit
703a941d
authored
Sep 09, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
eba90070
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
136 deletions
+136
-136
Program.cs
EduSpider/Program.cs
+0
-55
ClassInAccountManager.cs
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
+136
-81
No files found.
EduSpider/Program.cs
View file @
703a941d
...
@@ -54,60 +54,5 @@ namespace EduSpider
...
@@ -54,60 +54,5 @@ namespace EduSpider
Console
.
ReadLine
();
Console
.
ReadLine
();
Environment
.
Exit
(
0
);
Environment
.
Exit
(
0
);
}
}
#
region
异常
退出
chromedriver
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"FindWindow"
)]
private
extern
static
IntPtr
FindWindow
(
string
lpClassName
,
string
lpWindowName
);
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"SendMessage"
)]
public
static
extern
int
SendMessage
(
IntPtr
hWnd
,
int
Msg
,
int
wParam
,
int
lParam
);
public
const
int
SW_HIDE
=
0
;
public
const
int
SW_SHOW
=
5
;
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"ShowWindow"
)]
public
static
extern
int
ShowWindow
(
IntPtr
hwnd
,
int
nCmdShow
);
/// <summary>
/// 获取窗口句柄
/// </summary>
/// <returns></returns>
public
IntPtr
GetWindowHandle
()
{
string
name
=
(
Environment
.
CurrentDirectory
+
"\\chromedriver.exe"
);
IntPtr
hwd
=
FindWindow
(
null
,
name
);
return
hwd
;
}
/// <summary>
/// 关闭chromedriver窗口
/// </summary>
public
void
CloseWindow
()
{
try
{
IntPtr
hwd
=
GetWindowHandle
();
SendMessage
(
hwd
,
0x10
,
0
,
0
);
}
catch
{
}
}
/// <summary>
/// 退出chromedriver
/// </summary>
/// <param name="driver"></param>
public
void
CloseChromeDriver
(
IWebDriver
driver
)
{
try
{
driver
.
Quit
();
driver
.
Dispose
();
}
catch
{
}
CloseWindow
();
}
#
endregion
异常
退出
chromedriver
}
}
}
}
\ No newline at end of file
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
View file @
703a941d
...
@@ -10,6 +10,7 @@ using System.Drawing;
...
@@ -10,6 +10,7 @@ using System.Drawing;
using
System.IO
;
using
System.IO
;
using
System.Net
;
using
System.Net
;
using
System.Net.Http
;
using
System.Net.Http
;
using
System.Runtime.InteropServices
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
...
@@ -72,7 +73,7 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -72,7 +73,7 @@ namespace TicketSpider.Spiders.ClassInRule
IWebElement
pwdEle
;
IWebElement
pwdEle
;
var
option
=
new
FirefoxOptions
();
var
option
=
new
FirefoxOptions
();
option
.
AddArgument
(
"--incognito"
);
option
.
AddArgument
(
"--incognito"
);
string
IsOpenChrome
=
VTX
.
FW
.
Helper
.
ConfigHelper
.
GetAppsettings
(
"IsOpenChrome"
);
string
IsOpenChrome
=
VTX
.
FW
.
Helper
.
ConfigHelper
.
GetAppsettings
(
"IsOpenChrome"
);
if
(
IsOpenChrome
==
"1"
)
if
(
IsOpenChrome
==
"1"
)
{
{
option
.
AddArgument
(
"window-size=1920,1080"
);
option
.
AddArgument
(
"window-size=1920,1080"
);
...
@@ -94,14 +95,12 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -94,14 +95,12 @@ namespace TicketSpider.Spiders.ClassInRule
option
.
PageLoadStrategy
=
PageLoadStrategy
.
Eager
;
option
.
PageLoadStrategy
=
PageLoadStrategy
.
Eager
;
FirefoxDriverService
service
=
FirefoxDriverService
.
CreateDefaultService
(
Environment
.
CurrentDirectory
);
FirefoxDriverService
service
=
FirefoxDriverService
.
CreateDefaultService
(
Environment
.
CurrentDirectory
);
service
.
HideCommandPromptWindow
=
true
;
service
.
HideCommandPromptWindow
=
true
;
using
(
IWebDriver
driver
=
new
FirefoxDriver
(
service
,
option
))
IWebDriver
driver
=
new
FirefoxDriver
(
service
,
option
);
{
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
"开始登录"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
"开始登录"
);
try
try
{
{
driver
.
Navigate
().
GoToUrl
(
$"https://www.eeo.cn/cn/login"
);
driver
.
Navigate
().
GoToUrl
(
$"https://www.eeo.cn/cn/login"
);
ITimeouts
timeouts
=
driver
.
Manage
().
Timeouts
();
ITimeouts
timeouts
=
driver
.
Manage
().
Timeouts
();
//设置查找元素最大超时时间为30秒
//设置查找元素最大超时时间为30秒
timeouts
.
ImplicitWait
=
new
TimeSpan
(
0
,
0
,
30
);
timeouts
.
ImplicitWait
=
new
TimeSpan
(
0
,
0
,
30
);
...
@@ -126,18 +125,17 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -126,18 +125,17 @@ namespace TicketSpider.Spiders.ClassInRule
{
{
inputEle
.
SendKeys
(
"18140082327"
);
inputEle
.
SendKeys
(
"18140082327"
);
pwdEle
.
SendKeys
(
"ls123456"
);
pwdEle
.
SendKeys
(
"ls123456"
);
var
loginCount
=
0
;
var
buttonEle
=
driver
.
FindElement
(
By
.
CssSelector
(
".submit-btn"
));
var
buttonEle
=
driver
.
FindElement
(
By
.
CssSelector
(
".submit-btn"
));
Thread
.
Sleep
(
1000
);
Thread
.
Sleep
(
1000
);
//开始登录
//开始登录
buttonEle
.
Click
();
buttonEle
.
Click
();
//开始模拟登录
//开始模拟登录
while
(
true
)
for
(
var
loginCount
=
0
;
loginCount
<=
4
;
loginCount
++
)
{
{
loginCount
++;
InfoHelper
.
WriteLine
(
$"正在进行第
{
loginCount
}
次模拟登录..."
);
InfoHelper
.
WriteLine
(
$"正在进行第
{
loginCount
}
次模拟登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"正在进行第
{
loginCount
}
次模拟登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"正在进行第
{
loginCount
}
次模拟登录..."
);
var
login
=
FireFoxBeginSliderLoginHandler
(
ref
driver
);
var
login
=
FireFoxBeginSliderLoginHandler
(
driver
);
if
(
login
.
IsCompleted
)
if
(
login
.
IsCompleted
)
{
{
driver
.
SwitchTo
().
DefaultContent
();
driver
.
SwitchTo
().
DefaultContent
();
...
@@ -172,6 +170,7 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -172,6 +170,7 @@ namespace TicketSpider.Spiders.ClassInRule
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
CloseFireFoxDriver
(
driver
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"获取cooki失败,
{
ex
.
Message
}
"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"获取cooki失败,
{
ex
.
Message
}
"
);
InfoHelper
.
WriteLine
(
$"获取cooki失败,
{
ex
.
Message
}
"
);
InfoHelper
.
WriteLine
(
$"获取cooki失败,
{
ex
.
Message
}
"
);
}
}
...
@@ -181,13 +180,69 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -181,13 +180,69 @@ namespace TicketSpider.Spiders.ClassInRule
driver
.
Quit
();
driver
.
Quit
();
driver
.
Dispose
();
driver
.
Dispose
();
}
}
}
InfoHelper
.
WriteLine
(
"完成登录..."
);
InfoHelper
.
WriteLine
(
"完成登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"完成登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"完成登录..."
);
return
flag
;
return
flag
;
}
}
public
static
Task
FireFoxBeginSliderLoginHandler
(
ref
IWebDriver
driver
)
#
region
异常
退出
chromedriver
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"FindWindow"
)]
private
extern
static
IntPtr
FindWindow
(
string
lpClassName
,
string
lpWindowName
);
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"SendMessage"
)]
public
static
extern
int
SendMessage
(
IntPtr
hWnd
,
int
Msg
,
int
wParam
,
int
lParam
);
public
const
int
SW_HIDE
=
0
;
public
const
int
SW_SHOW
=
5
;
[
DllImport
(
"user32.dll"
,
EntryPoint
=
"ShowWindow"
)]
public
static
extern
int
ShowWindow
(
IntPtr
hwnd
,
int
nCmdShow
);
/// <summary>
/// 获取窗口句柄
/// </summary>
/// <returns></returns>
public
static
IntPtr
GetWindowHandle
()
{
string
name
=
(
Environment
.
CurrentDirectory
+
"\\geckodriver.exe"
);
IntPtr
hwd
=
FindWindow
(
null
,
name
);
return
hwd
;
}
/// <summary>
/// 关闭chromedriver窗口
/// </summary>
public
static
void
CloseWindow
()
{
try
{
IntPtr
hwd
=
GetWindowHandle
();
SendMessage
(
hwd
,
0x10
,
0
,
0
);
}
catch
{
}
}
/// <summary>
/// 退出chromedriver
/// </summary>
/// <param name="driver"></param>
public
static
void
CloseFireFoxDriver
(
IWebDriver
driver
)
{
try
{
driver
.
Quit
();
driver
.
Dispose
();
}
catch
{
}
CloseWindow
();
}
#
endregion
异常
退出
chromedriver
public
static
Task
FireFoxBeginSliderLoginHandler
(
IWebDriver
driver
)
{
{
//等待滑块加载
//等待滑块加载
Thread
.
Sleep
(
5000
);
Thread
.
Sleep
(
5000
);
...
@@ -237,7 +292,7 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -237,7 +292,7 @@ namespace TicketSpider.Spiders.ClassInRule
return
Task
.
CompletedTask
;
return
Task
.
CompletedTask
;
}
}
private
static
int
FireFoxGetBoundary
(
string
fileBgPath
,
string
fileBlockPath
)
private
static
int
FireFoxGetBoundary
(
string
fileBgPath
,
string
fileBlockPath
)
{
{
var
dirpath
=
$"
{
Environment
.
CurrentDirectory
}
\\geetest"
;
var
dirpath
=
$"
{
Environment
.
CurrentDirectory
}
\\geetest"
;
var
bgImg
=
Cv2
.
ImRead
(
fileBgPath
);
var
bgImg
=
Cv2
.
ImRead
(
fileBgPath
);
...
...
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