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
fb19b747
Commit
fb19b747
authored
May 25, 2022
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整
parent
3976aca0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
12 deletions
+42
-12
JObjectHelper.cs
EduSpider.Utility/JObjectHelper.cs
+3
-6
StudentManager.cs
EduSpider/Spiders/ClassInRule/StudentManager.cs
+39
-6
No files found.
EduSpider.Utility/JObjectHelper.cs
View file @
fb19b747
...
@@ -9,20 +9,17 @@ namespace EduSpider.Utility
...
@@ -9,20 +9,17 @@ namespace EduSpider.Utility
{
{
public
static
class
JObjectHelper
public
static
class
JObjectHelper
{
{
public
static
bool
TryFromString
(
this
JObject
obj
,
string
str
)
public
static
(
bool
flag
,
JObject
val
)
TryToJObject
(
this
string
str
)
{
{
var
flag
=
true
;
try
try
{
{
obj
=
JObject
.
Parse
(
str
);
return
(
true
,
JObject
.
Parse
(
str
)
);
}
}
catch
(
Exception
)
catch
(
Exception
)
{
{
flag
=
false
;
return
(
false
,
new
JObject
());
obj
=
new
JObject
();
}
}
return
flag
;
}
}
}
}
}
}
EduSpider/Spiders/ClassInRule/StudentManager.cs
View file @
fb19b747
using
EduSpider.Model.Entity
;
using
EduSpider.IRepository
;
using
EduSpider.Model.Entity
;
using
EduSpider.Repository
;
using
EduSpider.Repository
;
using
EduSpider.Utility
;
using
EduSpider.Utility
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
...
@@ -13,22 +14,27 @@ namespace EduSpider.Spiders.ClassInRule
...
@@ -13,22 +14,27 @@ namespace EduSpider.Spiders.ClassInRule
{
{
public
class
StudentManager
public
class
StudentManager
{
{
private
static
readonly
IStudentRepository
courseRepository
=
new
StudentRepository
();
public
async
void
RunAsync
(
string
cookie
)
public
async
void
RunAsync
(
string
cookie
)
{
{
var
request
=
Utility
.
HttpHelper
.
GenerateHttp
(
cookie
);
var
request
=
Utility
.
HttpHelper
.
GenerateHttp
(
cookie
);
int
pageIndex
=
1
,
pageCount
=
1
,
pageSize
=
100
00
;
int
pageIndex
=
1
,
pageCount
=
1
,
pageSize
=
5
00
;
while
(
pageIndex
<=
pageCount
)
while
(
pageIndex
<=
pageCount
)
{
{
Console
.
WriteLine
(
$"正在查询第
{
pageIndex
}
-
{
pageSize
}
页学员信息"
);
var
paramStr
=
$"page=
{
pageIndex
}
&perpage=
{
pageSize
}
&isdel=0"
;
var
paramStr
=
$"page=
{
pageIndex
}
&perpage=
{
pageSize
}
&isdel=0"
;
var
content
=
new
StringContent
(
paramStr
,
System
.
Text
.
Encoding
.
UTF8
,
"application/x-www-form-urlencoded"
);
var
content
=
new
StringContent
(
paramStr
,
System
.
Text
.
Encoding
.
UTF8
,
"application/x-www-form-urlencoded"
);
var
response
=
await
request
.
PostAsync
(
"https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage"
,
content
);
var
response
=
await
request
.
PostAsync
(
"https://console.eeo.cn/saasajax/student.ajax.php?action=getSchoolStudentListByPage"
,
content
);
var
resultStr
=
response
.
Content
.
ReadAsStringAsync
().
Result
??
string
.
Empty
;
var
resultStr
=
response
.
Content
.
ReadAsStringAsync
().
Result
??
string
.
Empty
;
var
result
=
new
JObject
();
var
result
=
resultStr
.
TryToJObject
();
if
(
result
.
TryFromString
(
resultStr
))
if
(
result
.
flag
)
{
{
var
data
=
(
result
.
ContainsKey
(
"data"
)
?
result
[
"data"
]
:
new
JObject
())
as
JObject
;
var
data
=
(
result
.
val
.
ContainsKey
(
"data"
)
?
result
.
val
[
"data"
]
:
new
JObject
())
as
JObject
;
if
(
data
.
ContainsKey
(
"totalStudentNum"
))
{
if
(
data
.
ContainsKey
(
"totalStudentNum"
))
{
#
region
更新
PageCount
#
region
更新
PageCount
...
@@ -38,11 +44,38 @@ namespace EduSpider.Spiders.ClassInRule
...
@@ -38,11 +44,38 @@ namespace EduSpider.Spiders.ClassInRule
}
}
#
endregion
#
endregion
var
students
=
JsonConvert
.
DeserializeObject
<
RB_Student
>(
data
.
GetString
(
"studentList"
));
#
region
组装实体
var
stus
=
new
List
<
RB_Student
>();
var
stuArray
=
(
data
[
"studentList"
]
as
JArray
);
foreach
(
JObject
x
in
stuArray
)
{
stus
.
Add
(
new
RB_Student
()
{
AddTime
=
ConvertHelper
.
UnixToDateTime
(
x
.
GetString
(
"addTime"
)),
StudentAccount
=
x
.
GetString
(
"studentAccount"
),
Isdel
=
x
.
GetInt
(
"isdel"
,
0
),
IsGroup
=
x
.
GetInt
(
"isGroup"
,
0
),
StudId
=
x
.
GetInt
(
"studId"
,
0
),
Progress
=
x
.
GetString
(
"progress"
),
PublicResourceStatus
=
x
.
GetInt
(
"publicResourceStatus"
,
0
),
ServeState
=
x
.
GetInt
(
"serveState"
,
0
),
StudentName
=
x
.
GetString
(
"studentName"
),
StudentUid
=
x
.
GetInt
(
"studentUid"
,
0
),
Stuno
=
x
.
GetString
(
"stuno"
),
});
}
courseRepository
.
BatchSetStudent
(
stus
);
Console
.
WriteLine
(
$"已导入第
{
pageIndex
}
-
{
pageSize
}
页学员信息"
);
#
endregion
}
}
}
}
pageIndex
++;
}
}
Console
.
WriteLine
(
"学员同步完成"
);
}
}
}
}
...
...
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