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