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
fa09a4b1
Commit
fa09a4b1
authored
Jun 16, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
f24495c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
10 deletions
+75
-10
Program.cs
EduSpider/Program.cs
+57
-0
ClassInAccountManager.cs
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
+18
-10
No files found.
EduSpider/Program.cs
View file @
fa09a4b1
using
EduSpider.Spiders.SchoolHouseKeeper
;
using
EduSpider.Spiders.SchoolHouseKeeper
;
using
OpenQA.Selenium
;
using
System
;
using
System
;
using
System.Runtime.InteropServices
;
using
System.ServiceProcess
;
using
System.ServiceProcess
;
using
System.Threading
;
using
System.Threading
;
using
TicketSpider.Spiders.ClassInRule
;
using
TicketSpider.Spiders.ClassInRule
;
...
@@ -35,5 +37,60 @@ namespace EduSpider
...
@@ -35,5 +37,60 @@ 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 @
fa09a4b1
...
@@ -68,7 +68,7 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -68,7 +68,7 @@ namespace TicketSpider.Spiders.ClassInRule
IWebElement
pwdEle
;
IWebElement
pwdEle
;
var
option
=
new
ChromeOptions
();
var
option
=
new
ChromeOptions
();
option
.
AddArgument
(
"--incognito"
);
option
.
AddArgument
(
"--incognito"
);
option
.
AddArgument
(
"headless"
);
//
option.AddArgument("headless");
option
.
AddArgument
(
"disable-infobars"
);
option
.
AddArgument
(
"disable-infobars"
);
option
.
AddArgument
(
"window-size=1920,1080"
);
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"
);
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"
);
...
@@ -101,11 +101,11 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -101,11 +101,11 @@ namespace TicketSpider.Spiders.ClassInRule
var
login
=
BeginSliderLoginHandler
(
ref
driver
);
var
login
=
BeginSliderLoginHandler
(
ref
driver
);
if
(
login
.
IsCompleted
)
if
(
login
.
IsCompleted
)
{
{
driver
.
SwitchTo
().
DefaultContent
();
Thread
.
Sleep
(
1000
*
5
);
//driver.SwitchTo().DefaultContent();
Console
.
WriteLine
(
$"操作完成,正在等待结果"
);
Console
.
WriteLine
(
$"操作完成,正在等待结果"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"操作完成,正在等待结果"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"操作完成,正在等待结果"
);
//睡眠1秒,等待跳转
//睡眠1秒,等待跳转
Thread
.
Sleep
(
5
*
1000
);
if
(
driver
.
Url
.
Contains
(
"www.eeo.cn/cn/login"
))
if
(
driver
.
Url
.
Contains
(
"www.eeo.cn/cn/login"
))
{
{
Console
.
WriteLine
(
$"模拟登录失败,准备重新执行..."
);
Console
.
WriteLine
(
$"模拟登录失败,准备重新执行..."
);
...
@@ -129,9 +129,9 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -129,9 +129,9 @@ namespace TicketSpider.Spiders.ClassInRule
}
}
else
else
{
{
Thread
.
Sleep
(
3
*
1000
)
;
var
cookies
=
driver
.
Manage
().
Cookies
.
AllCookies
;
//处理
//处理
foreach
(
var
item
in
driver
.
Manage
().
Cookies
.
AllC
ookies
)
foreach
(
var
item
in
c
ookies
)
{
{
_loginCookies
+=
item
.
Name
+
"="
+
item
.
Value
+
";"
;
_loginCookies
+=
item
.
Name
+
"="
+
item
.
Value
+
";"
;
}
}
...
@@ -153,8 +153,11 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -153,8 +153,11 @@ namespace TicketSpider.Spiders.ClassInRule
{
{
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"获取cooki失败,
{
ex
.
Message
}
"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"获取cooki失败,
{
ex
.
Message
}
"
);
Console
.
WriteLine
(
$"获取cooki失败,
{
ex
.
Message
}
"
);
Console
.
WriteLine
(
$"获取cooki失败,
{
ex
.
Message
}
"
);
Thread
.
Sleep
(
1000
*
4
);
}
}
driver
.
Close
();
driver
.
Quit
();
driver
.
Quit
();
driver
.
Dispose
();
Console
.
WriteLine
(
"完成登录..."
);
Console
.
WriteLine
(
"完成登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"完成登录..."
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"完成登录..."
);
return
flag
;
return
flag
;
...
@@ -196,20 +199,25 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -196,20 +199,25 @@ namespace TicketSpider.Spiders.ClassInRule
var
d1
=
Math
.
Round
(
bgX
*
0.8
);
var
d1
=
Math
.
Round
(
bgX
*
0.8
);
var
d2
=
Math
.
Round
(
bgX
*
0.1
);
var
d2
=
Math
.
Round
(
bgX
*
0.1
);
var
d3
=
Math
.
Round
(
bgX
*
0.1
);
var
d3
=
Math
.
Round
(
bgX
*
0.1
);
Console
.
WriteLine
(
"d1:"
+
d1
);
action
.
MoveByOffset
((
int
)
d1
,
1
);
action
.
MoveByOffset
((
int
)
d1
,
1
);
Thread
.
Sleep
(
new
Random
().
Next
(
100
)
+
150
);
Thread
.
Sleep
(
new
Random
().
Next
(
100
)
+
150
);
Console
.
WriteLine
(
"d2:"
+
d2
);
action
.
MoveByOffset
((
int
)
d2
,
1
);
action
.
MoveByOffset
((
int
)
d2
,
1
);
Thread
.
Sleep
(
new
Random
().
Next
(
100
)
+
150
);
Thread
.
Sleep
(
new
Random
().
Next
(
100
)
+
150
);
Console
.
WriteLine
(
"d3:"
+
d3
);
action
.
MoveByOffset
((
int
)
d3
,
1
);
action
.
MoveByOffset
((
int
)
d3
,
1
);
action
.
MoveByOffset
((
bgX
-
(
int
)
d1
-
(
int
)
d2
-
(
int
)
d3
),
1
);
int
last
=
(
bgX
-
(
int
)
d1
-
(
int
)
d2
-
(
int
)
d3
);
Console
.
WriteLine
(
"last:"
+
last
);
action
.
MoveByOffset
(
last
,
1
);
Thread
.
Sleep
(
2000
);
Thread
.
Sleep
(
2000
);
#
endregion
#
endregion
action
.
Release
(
sliderButton
);
action
.
Release
(
sliderButton
);
action
.
Build
().
Perform
();
action
.
Build
().
Perform
();
driver
.
SwitchTo
().
DefaultContent
();
driver
.
SwitchTo
().
DefaultContent
();
}
}
File
.
Delete
(
fileBgPath
);
File
.
Delete
(
fileBgPath
);
...
@@ -243,7 +251,7 @@ namespace TicketSpider.Spiders.ClassInRule
...
@@ -243,7 +251,7 @@ namespace TicketSpider.Spiders.ClassInRule
var
dirpath
=
$"
{
Environment
.
CurrentDirectory
}
\\geetest"
;
var
dirpath
=
$"
{
Environment
.
CurrentDirectory
}
\\geetest"
;
Cv2
.
ImWrite
(
$"
{
dirpath
}
\\
{
DateTime
.
Now
.
Ticks
}
.png"
,
bgImg
);
Cv2
.
ImWrite
(
$"
{
dirpath
}
\\
{
DateTime
.
Now
.
Ticks
}
.png"
,
bgImg
);
return
maxLoc
.
X
-
2
0
;
return
maxLoc
.
X
-
2
5
;
}
}
private
static
void
HeartLine
()
private
static
void
HeartLine
()
...
...
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