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
4237f42e
Commit
4237f42e
authored
Sep 06, 2022
by
chenweitao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'working' into 'master'
Working See merge request
!201
parents
2782632a
50407ed7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
7 deletions
+10
-7
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboHotSearchCrawler.java
+1
-0
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboTopicCrawler.java
+9
-7
No files found.
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboHotSearchCrawler.java
View file @
4237f42e
...
...
@@ -505,6 +505,7 @@ public class WeiboHotSearchCrawler {
String
url
=
"https://s.weibo.com/weibo?q="
+
encode
+
"&Refer=top"
;
String
htmlBody
=
null
;
Map
<
String
,
String
>
headerMap
=
new
HashMap
<>();
//该cookie有效期一年,微博pc端获取游客cookie链接 https://s.weibo.com/top/summary?cate=realtimehot
headerMap
.
put
(
"Cookie"
,
"SUB=_2AkMUShJMf8NxqwJRmP0RyWvgb4RwwgnEieKiFuOXJRMxHRl-yT92qlQvtRB6P8o8oso9Ew-s6vf16fdCca-Xz6DwwAMH; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WFdAobr6HdAbgQQ9vbUQKDx"
);
Request
request
=
RequestUtils
.
wrapGet
(
url
,
headerMap
);
Response
response
=
httpBoot
.
syncCall
(
request
,
ProxySupplier
.
NAT_HEAVY_PROXY
);
...
...
src/main/java/com/zhiwei/searchhotcrawler/crawler/WeiboTopicCrawler.java
View file @
4237f42e
...
...
@@ -222,8 +222,8 @@ public class WeiboTopicCrawler {
*/
public
static
List
<
HotSearchList
>
startCrawlerByPc
(
Date
date
){
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
for
(
int
page
=
1
;
page
<=
2
;
page
++){
String
pageUrl
=
"https://weibo.com/ajax/statuses/topic_band?sid=v_weibopro&category=all&page="
+
page
+
"&count=
5
0"
;
for
(
int
page
=
1
;
page
<=
6
;
page
++){
String
pageUrl
=
"https://weibo.com/ajax/statuses/topic_band?sid=v_weibopro&category=all&page="
+
page
+
"&count=
1
0"
;
Request
request
=
RequestUtils
.
wrapGet
(
pageUrl
);
String
htmlBody
=
null
;
//重试三次
...
...
@@ -236,8 +236,12 @@ public class WeiboTopicCrawler {
}
else
{
htmlBody
=
response
.
bodyString
();
}
if
(
StringUtils
.
isNotBlank
(
htmlBody
))
{
topicList
.
addAll
(
parseTopicPcHtml
(
htmlBody
,
date
));
if
(
htmlBody
.
contains
(
"data"
)
&&
Objects
.
nonNull
(
JSONObject
.
parseObject
(
htmlBody
).
get
(
"data"
)))
{
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
JSONArray
statuses
=
data
.
getJSONArray
(
"statuses"
);
if
(
statuses
.
size
()>
0
)
{
topicList
.
addAll
(
parseTopicPcHtml
(
statuses
,
date
));
}
break
;
}
else
{
log
.
info
(
"下载榜单列表页面时数据格式错误,页面为:{}"
,
htmlBody
);
...
...
@@ -247,10 +251,8 @@ public class WeiboTopicCrawler {
return
topicList
;
}
private
static
List
<
HotSearchList
>
parseTopicPcHtml
(
String
htmlBod
y
,
Date
date
)
{
private
static
List
<
HotSearchList
>
parseTopicPcHtml
(
JSONArray
jsonArra
y
,
Date
date
)
{
try
{
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
JSONArray
jsonArray
=
data
.
getJSONArray
(
"statuses"
);
List
<
HotSearchList
>
topicList
=
new
ArrayList
<>();
for
(
int
j
=
0
;
j
<
jsonArray
.
size
();
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