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
9a3f1625
Commit
9a3f1625
authored
Dec 22, 2021
by
leiliangliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新虎嗅采集程序
parent
310520db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
28 deletions
+21
-28
src/main/java/com/zhiwei/searchhotcrawler/crawler/HuXiuHotSearchCrawler.java
+21
-28
No files found.
src/main/java/com/zhiwei/searchhotcrawler/crawler/HuXiuHotSearchCrawler.java
View file @
9a3f1625
package
com
.
zhiwei
.
searchhotcrawler
.
crawler
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.crawler.core.HttpBoot
;
import
com.zhiwei.crawler.core.proxy.ProxyHolder
;
import
com.zhiwei.crawler.core.utils.RequestUtils
;
...
...
@@ -73,35 +75,26 @@ public class HuXiuHotSearchCrawler {
//解析页面数据
private
static
List
<
HotSearchList
>
ansysData
(
String
htmlBody
,
Date
date
)
{
ArrayList
<
HotSearchList
>
list
=
new
ArrayList
<>();
String
webSite
=
"https://www.huxiu.com"
;
try
{
//获取Document文档对象
Document
document
=
Jsoup
.
parse
(
htmlBody
);
//获取元素集合
Elements
elements
=
document
.
select
(
"div.hot__list"
).
select
(
"div.focus-item"
);
if
(
Objects
.
nonNull
(
elements
)
&&
!
elements
.
isEmpty
()){
// 获取排名rank
Integer
rank
=
0
;
for
(
Element
element
:
elements
)
{
try
{
rank
++;
//获取关键词
String
keyWord
=
element
.
select
(
"p"
).
text
();
//获取关键词相关链接
String
href
=
element
.
select
(
"a.focus-item__left"
).
attr
(
"href"
);
String
url
=
webSite
+
href
;
//获取讨论量
String
comment
=
element
.
select
(
"i"
).
first
().
text
();
Long
commentCount
=
Long
.
valueOf
(
comment
);
String
topicLead
=
null
;
long
count
=
0L
;
HotSearchList
hotSearchList
=
new
HotSearchList
(
url
,
keyWord
,
count
,
rank
,
HotSearchType
.
虎嗅热文推荐
.
name
(),
commentCount
,
topicLead
,
date
);
list
.
add
(
hotSearchList
);
}
catch
(
NumberFormatException
e
)
{
log
.
error
(
"解析虎嗅热文推荐时出现解析错误"
,
e
);
}
}
String
substring
=
htmlBody
.
substring
(
htmlBody
.
indexOf
(
"articleHot"
)
+
12
,
htmlBody
.
indexOf
(
"momentList"
)
-
2
);
JSONArray
arr
=
JSONObject
.
parseArray
(
substring
);
//获取每个jsonObject对象的值
Integer
rank
=
0
;
for
(
Object
object
:
arr
)
{
rank
++;
JSONObject
json
=
(
JSONObject
)
JSONObject
.
toJSON
(
object
);
//获取标题
String
title
=
json
.
getString
(
"title"
);
//获取链接
String
url
=
json
.
getString
(
"share_url"
);
//获取讨论量
JSONObject
countInfo
=
json
.
getJSONObject
(
"count_info"
);
String
commentnum
=
countInfo
.
getString
(
"commentnum"
);
Long
commentCount
=
Long
.
valueOf
(
commentnum
);
String
topicLead
=
null
;
long
count
=
0L
;
HotSearchList
hotSearchList
=
new
HotSearchList
(
url
,
title
,
count
,
rank
,
HotSearchType
.
虎嗅热文推荐
.
name
(),
commentCount
,
topicLead
,
date
);
list
.
add
(
hotSearchList
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析虎嗅热文推荐时出现解析错误,数据不是json结构"
,
e
);
...
...
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