Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
searchhotcrawler
Overview
Overview
Details
Activity
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
zhiwei
searchhotcrawler
Commits
50407ed7
Commit
50407ed7
authored
Sep 06, 2022
by
leiliangliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新微博话题采集程序
parent
2eda193a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboTopicCrawler.java
+9
-7
No files found.
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboTopicCrawler.java
View file @
50407ed7
...
@@ -222,8 +222,8 @@ public class WeiboTopicCrawler {
...
@@ -222,8 +222,8 @@ public class WeiboTopicCrawler {
*/
*/
public
static
List
<
HotSearchList
>
startCrawlerByPc
(
Date
date
){
public
static
List
<
HotSearchList
>
startCrawlerByPc
(
Date
date
){
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
for
(
int
page
=
1
;
page
<=
2
;
page
++){
for
(
int
page
=
1
;
page
<=
6
;
page
++){
String
pageUrl
=
"https://weibo.com/ajax/statuses/topic_band?sid=v_weibopro&category=all&page="
+
page
+
"&count=
5
0"
;
String
pageUrl
=
"https://weibo.com/ajax/statuses/topic_band?sid=v_weibopro&category=all&page="
+
page
+
"&count=
1
0"
;
Request
request
=
RequestUtils
.
wrapGet
(
pageUrl
);
Request
request
=
RequestUtils
.
wrapGet
(
pageUrl
);
String
htmlBody
=
null
;
String
htmlBody
=
null
;
//重试三次
//重试三次
...
@@ -236,8 +236,12 @@ public class WeiboTopicCrawler {
...
@@ -236,8 +236,12 @@ public class WeiboTopicCrawler {
}
else
{
}
else
{
htmlBody
=
response
.
bodyString
();
htmlBody
=
response
.
bodyString
();
}
}
if
(
StringUtils
.
isNotBlank
(
htmlBody
))
{
if
(
htmlBody
.
contains
(
"data"
)
&&
Objects
.
nonNull
(
JSONObject
.
parseObject
(
htmlBody
).
get
(
"data"
)))
{
topicList
.
addAll
(
parseTopicPcHtml
(
htmlBody
,
date
));
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
JSONArray
statuses
=
data
.
getJSONArray
(
"statuses"
);
if
(
statuses
.
size
()>
0
)
{
topicList
.
addAll
(
parseTopicPcHtml
(
statuses
,
date
));
}
break
;
break
;
}
else
{
}
else
{
log
.
info
(
"下载榜单列表页面时数据格式错误,页面为:{}"
,
htmlBody
);
log
.
info
(
"下载榜单列表页面时数据格式错误,页面为:{}"
,
htmlBody
);
...
@@ -247,10 +251,8 @@ public class WeiboTopicCrawler {
...
@@ -247,10 +251,8 @@ public class WeiboTopicCrawler {
return
topicList
;
return
topicList
;
}
}
private
static
List
<
HotSearchList
>
parseTopicPcHtml
(
String
htmlBod
y
,
Date
date
)
{
private
static
List
<
HotSearchList
>
parseTopicPcHtml
(
JSONArray
jsonArra
y
,
Date
date
)
{
try
{
try
{
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
JSONArray
jsonArray
=
data
.
getJSONArray
(
"statuses"
);
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
jsonArray
.
size
();
j
++){
for
(
int
j
=
0
;
j
<
jsonArray
.
size
();
j
++){
JSONObject
card
=
jsonArray
.
getJSONObject
(
j
);
JSONObject
card
=
jsonArray
.
getJSONObject
(
j
);
...
...
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