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
852eb413
Commit
852eb413
authored
May 25, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/viitto/eduspider
parents
6ebc1f63
fb19b747
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 @
852eb413
...
...
@@ -9,20 +9,17 @@ namespace EduSpider.Utility
{
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
{
obj
=
JObject
.
Parse
(
str
);
return
(
true
,
JObject
.
Parse
(
str
)
);
}
catch
(
Exception
)
{
flag
=
false
;
obj
=
new
JObject
();
return
(
false
,
new
JObject
());
}
return
flag
;
}
}
}
EduSpider/Spiders/ClassInRule/StudentManager.cs
View file @
852eb413
using
EduSpider.Model.Entity
;
using
EduSpider.IRepository
;
using
EduSpider.Model.Entity
;
using
EduSpider.Repository
;
using
EduSpider.Utility
;
using
Newtonsoft.Json
;
...
...
@@ -13,22 +14,27 @@ namespace EduSpider.Spiders.ClassInRule
{
public
class
StudentManager
{
private
static
readonly
IStudentRepository
courseRepository
=
new
StudentRepository
();
public
async
void
RunAsync
(
string
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
)
{
Console
.
WriteLine
(
$"正在查询第
{
pageIndex
}
-
{
pageSize
}
页学员信息"
);
var
paramStr
=
$"page=
{
pageIndex
}
&perpage=
{
pageSize
}
&isdel=0"
;
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
resultStr
=
response
.
Content
.
ReadAsStringAsync
().
Result
??
string
.
Empty
;
var
result
=
new
JObject
();
if
(
result
.
TryFromString
(
resultStr
))
var
result
=
resultStr
.
TryToJObject
();
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"
))
{
#
region
更新
PageCount
...
...
@@ -38,11 +44,38 @@ namespace EduSpider.Spiders.ClassInRule
}
#
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