Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media_data_crawler
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
media_data_crawler
Commits
9d3ee2e7
Commit
9d3ee2e7
authored
Mar 22, 2018
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复百度新闻根据标题匹配数据解析错误bug
parent
ee34a906
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
+26
-2
src/main/java/com/zhiwei/media_data_crawler/crawler/BaiduNewsCrawlerParse.java
+26
-2
No files found.
src/main/java/com/zhiwei/media_data_crawler/crawler/BaiduNewsCrawlerParse.java
View file @
9d3ee2e7
...
...
@@ -246,7 +246,6 @@ public class BaiduNewsCrawlerParse extends HttpClientTemplateOK {
link
=
element
.
select
(
"h3.c-title"
).
select
(
"a"
).
attr
(
"href"
);
title
=
element
.
select
(
"h3.c-title"
).
select
(
"a"
).
text
();
soureAndtime
=
element
.
select
(
"div.c-row"
).
select
(
"p.c-author"
).
html
();
System
.
out
.
println
(
"time========"
+
soureAndtime
);
/** 截取时间 */
if
(
soureAndtime
.
contains
(
" "
))
{
String
soureAndtimes
[]
=
soureAndtime
.
split
(
" "
);
...
...
@@ -350,7 +349,7 @@ public class BaiduNewsCrawlerParse extends HttpClientTemplateOK {
String
otherUrl
=
element
.
select
(
"div.c-title-author"
).
select
(
"a"
).
attr
(
"href"
);
if
(
otherUrl
!=
null
&&
!
otherUrl
.
equals
(
""
))
{
String
otherLink
=
"http://news.baidu.com"
+
otherUrl
;
List
<
NewsData
>
otherDataList
=
getOherBaiduNewsData
(
otherLink
,
word
,
proxy
);
List
<
NewsData
>
otherDataList
=
getOherBaiduNewsData
ByTitle
(
otherLink
,
word
,
proxy
);
list
.
addAll
(
otherDataList
);
ZhiWeiTools
.
sleep
(
100
);
}
...
...
@@ -406,6 +405,31 @@ public class BaiduNewsCrawlerParse extends HttpClientTemplateOK {
}
return
list
;
}
public
static
List
<
NewsData
>
getOherBaiduNewsDataByTitle
(
String
url
,
String
word
,
Proxy
proxy
)
throws
Exception
{
List
<
NewsData
>
list
=
new
ArrayList
<
NewsData
>();
int
page
=
0
;
boolean
more
=
true
;
while
(
more
)
{
// 最大页数为20
if
(
page
>
20
)
{
more
=
false
;
}
String
htmlBody
=
downloadHtml
(
url
,
proxy
,
page
);
if
(
htmlBody
!=
null
)
{
Map
<
String
,
Object
>
dataMap
=
analysisDataByTitle
(
htmlBody
,
null
,
word
);
List
<
NewsData
>
dataList
=
(
List
<
NewsData
>)
dataMap
.
get
(
"data"
);
list
.
addAll
(
dataList
);
more
=
(
Boolean
)
dataMap
.
get
(
"more"
);
}
else
{
more
=
false
;
}
page
++;
}
return
list
;
}
/**
* @Title: getUrl
...
...
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