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
ac91d71f
Commit
ac91d71f
authored
Sep 26, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增缓存
parent
ac0ca2db
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
56 deletions
+126
-56
CacheKey.cs
EduSpider.Cache/CacheKey.cs
+2
-0
UserReidsCache.cs
EduSpider.Cache/User/UserReidsCache.cs
+47
-1
EduSpider.csproj
EduSpider/EduSpider.csproj
+1
-0
ClassInAccountManager.cs
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
+61
-54
ClassInFlow.cs
EduSpider/Spiders/ClassInRule/ClassInFlow.cs
+15
-1
No files found.
EduSpider.Cache/CacheKey.cs
View file @
ac91d71f
...
...
@@ -10,5 +10,7 @@ namespace EduSpider.Cache
/// 用户登录缓存Key
/// </summary>
public
static
string
User_Login_Key
=
"JJSW_Login_"
;
public
static
string
ClassIn_Cookie_Key
=
"ClassInCookie"
;
}
}
EduSpider.Cache/User/UserReidsCache.cs
View file @
ac91d71f
...
...
@@ -40,6 +40,44 @@ namespace EduSpider.Cache.User
}
}
/// <summary>
/// 设置Class登录Cookie
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="model"></param>
/// <param name="JwtExpirTime"></param>
public
static
void
ClassInCookieSet
(
string
cacheKey
,
ClassInTokenItem
model
,
int
JwtExpirTime
)
{
try
{
TimeSpan
ts
=
GetExpirTime
(
JwtExpirTime
);
redis
.
StringSet
<
ClassInTokenItem
>(
cacheKey
,
model
,
ts
);
}
catch
(
Exception
ex
)
{
LogHelper
.
WriteError
(
"ClassInCookieSet"
,
"缓存设置失败"
,
ex
);
}
}
/// <summary>
/// 获取ClassInToken
/// </summary>
/// <param name="cacheKey"></param>
/// <returns></returns>
public
static
ClassInTokenItem
GetClassInCookie
(
string
cacheKey
)
{
ClassInTokenItem
tokenInfo
=
new
ClassInTokenItem
();
try
{
tokenInfo
=
redis
.
StringGet
<
ClassInTokenItem
>(
cacheKey
);
}
catch
(
Exception
ex
)
{
LogHelper
.
WriteError
(
"GetUserLoginInfo"
,
"获取缓存失败"
,
ex
);
}
return
tokenInfo
;
}
/// <summary>
/// 获取缓存时长
/// </summary>
...
...
@@ -81,6 +119,8 @@ namespace EduSpider.Cache.User
}
}
/// <summary>
/// 获取缓存
/// </summary>
...
...
@@ -92,12 +132,13 @@ namespace EduSpider.Cache.User
object
info
=
redis
.
StringGet
<
object
>(
cacheKey
);
return
info
;
}
catch
(
Exception
)
catch
(
Exception
ex
)
{
return
""
;
}
}
/// <summary>
/// 账号仓储层对象
/// </summary>
...
...
@@ -160,4 +201,9 @@ namespace EduSpider.Cache.User
}
}
public
class
ClassInTokenItem
{
public
string
CacheCookies
{
get
;
set
;
}
}
}
\ No newline at end of file
EduSpider/EduSpider.csproj
View file @
ac91d71f
...
...
@@ -49,6 +49,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EduSpider.Cache\EduSpider.Cache.csproj" />
<ProjectReference Include="..\EduSpider.IRepository\EduSpider.IRepository.csproj" />
<ProjectReference Include="..\EduSpider.Model\EduSpider.Model.csproj" />
<ProjectReference Include="..\EduSpider.Repository\EduSpider.Repository.csproj" />
...
...
EduSpider/Spiders/ClassInRule/ClassInAccountManager.cs
View file @
ac91d71f
...
...
@@ -39,10 +39,8 @@ namespace TicketSpider.Spiders.ClassInRule
if
(
string
.
IsNullOrEmpty
(
_loginCookies
))
{
_loginCookies
=
string
.
Empty
;
var
cnt
=
0
;
Random
r
=
new
Random
();
while
(
cnt
<
4
)
{
cnt
++;
...
...
@@ -71,8 +69,7 @@ namespace TicketSpider.Spiders.ClassInRule
public
static
bool
RunAsync
()
{
var
flag
=
false
;
IWebElement
inputEle
;
IWebElement
pwdEle
;
var
option
=
new
FirefoxOptions
();
option
.
AddArgument
(
"--incognito"
);
string
IsOpenChrome
=
VTX
.
FW
.
Helper
.
ConfigHelper
.
GetAppsettings
(
"IsOpenChrome"
);
...
...
@@ -86,9 +83,8 @@ namespace TicketSpider.Spiders.ClassInRule
//option.AddArgument("headless");
//火狐隐身模式
option
.
AddArgument
(
"--headless"
);
//option.AddArgument("--disable-gpu");
// option.AddArgument("ingore-certificate-errors");
// option.AddArgument("ingore-certificat
e-errors");
}
option
.
AddArgument
(
"--disable-infobars"
);
option
.
AddArgument
(
"window-size=1920*1080"
);
...
...
@@ -112,7 +108,10 @@ namespace TicketSpider.Spiders.ClassInRule
//等待页面元素加载完成
//默认等待100秒
WebDriverWait
wait
=
new
WebDriverWait
(
driver
,
TimeSpan
.
FromSeconds
(
100
));
IWebElement
inputEle
;
IWebElement
pwdEle
;
try
{
//等待页面上按钮加载
inputEle
=
wait
.
Until
((
d
)
=>
{
...
...
@@ -126,13 +125,21 @@ namespace TicketSpider.Spiders.ClassInRule
{
inputEle
.
SendKeys
(
"18140082327"
);
pwdEle
.
SendKeys
(
"ls123456"
);
}
}
catch
(
Exception
ex
)
{
InfoHelper
.
WriteLine
(
"未知异常,程序退出"
);
VTX
.
FW
.
Helper
.
LogHelper
.
WriteInfo
(
"RunAsync"
,
$"未知异常,程序退出"
);
}
var
buttonEle
=
driver
.
FindElement
(
By
.
CssSelector
(
".submit-btn"
));
Thread
.
Sleep
(
1000
);
//开始登录
buttonEle
.
Click
();
//开始模拟登录
Random
r
=
new
Random
();
for
(
var
loginCount
=
1
;
loginCount
<=
3
;
loginCount
++)
for
(
var
loginCount
=
1
;
loginCount
<=
2
;
loginCount
++)
{
if
(
loginCount
>
1
)
{
...
...
@@ -172,7 +179,7 @@ namespace TicketSpider.Spiders.ClassInRule
break
;
}
}
}
}
catch
(
Exception
ex
)
{
...
...
EduSpider/Spiders/ClassInRule/ClassInFlow.cs
View file @
ac91d71f
...
...
@@ -18,7 +18,21 @@ namespace TicketSpider.Spiders.ClassInRule
if
(
string
.
IsNullOrEmpty
(
loginCookies
))
{
ClassInAccountManager
.
ClearCookie
();
string
key
=
EduSpider
.
Cache
.
CacheKey
.
ClassIn_Cookie_Key
;
int
ExpirTime
=
60
*
60
*
12
;
var
cacheCookie
=
EduSpider
.
Cache
.
User
.
UserReidsCache
.
GetClassInCookie
(
key
);
if
(
cacheCookie
!=
null
&&
!
string
.
IsNullOrEmpty
(
cacheCookie
.
CacheCookies
.
ToString
()))
{
loginCookies
=
cacheCookie
.
CacheCookies
;
}
else
{
loginCookies
=
ClassInAccountManager
.
GetInstance
();
if
(!
string
.
IsNullOrEmpty
(
loginCookies
))
{
EduSpider
.
Cache
.
User
.
UserReidsCache
.
ClassInCookieSet
(
key
,
new
EduSpider
.
Cache
.
User
.
ClassInTokenItem
()
{
CacheCookies
=
loginCookies
},
ExpirTime
);
}
}
}
InfoHelper
.
WriteLine
(
"cookies:"
+
loginCookies
);
...
...
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