Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
toutiao
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
toutiao
Commits
2191591c
Commit
2191591c
authored
Sep 11, 2018
by
yangchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加代理
parent
74dd753d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
src/main/java/com/zhiwei/toutiao/parse/TouTiaoCommentParse.java
+8
-9
No files found.
src/main/java/com/zhiwei/toutiao/parse/TouTiaoCommentParse.java
View file @
2191591c
...
@@ -13,8 +13,6 @@ import org.slf4j.LoggerFactory;
...
@@ -13,8 +13,6 @@ import org.slf4j.LoggerFactory;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.crawler.core.HttpBoot
;
import
com.zhiwei.crawler.core.RequestUtils
;
import
com.zhiwei.tools.httpclient.HttpClientTemplateOK
;
import
com.zhiwei.tools.httpclient.HttpClientTemplateOK
;
import
com.zhiwei.tools.tools.ZhiWeiTools
;
import
com.zhiwei.tools.tools.ZhiWeiTools
;
import
com.zhiwei.toutiao.bean.TouTiaoComment
;
import
com.zhiwei.toutiao.bean.TouTiaoComment
;
...
@@ -49,7 +47,7 @@ public class TouTiaoCommentParse {
...
@@ -49,7 +47,7 @@ public class TouTiaoCommentParse {
String
group_id
=
getGroupId
(
url
,
proxy
);
String
group_id
=
getGroupId
(
url
,
proxy
);
//查询评论总页数
//查询评论总页数
if
(
group_id
!=
null
){
if
(
group_id
!=
null
){
int
page
=
getPage
(
group_id
);
int
page
=
getPage
(
group_id
,
proxy
);
if
(
returnCount
>
0
){
if
(
returnCount
>
0
){
int
pageMax
=
(
int
)
Math
.
ceil
((
double
)
returnCount
/
20.0
);
int
pageMax
=
(
int
)
Math
.
ceil
((
double
)
returnCount
/
20.0
);
if
(
page
>=
pageMax
){
if
(
page
>=
pageMax
){
...
@@ -66,7 +64,7 @@ public class TouTiaoCommentParse {
...
@@ -66,7 +64,7 @@ public class TouTiaoCommentParse {
headerMap
.
put
(
"Host"
,
"is.snssdk.com"
);
headerMap
.
put
(
"Host"
,
"is.snssdk.com"
);
for
(
int
j
=
1
;
j
<=
3
;
j
++){
for
(
int
j
=
1
;
j
<=
3
;
j
++){
try
{
try
{
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
null
,
headerMap
);
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
)
if
(
htmlBody
!=
null
)
{
{
List
<
TouTiaoComment
>
commentes
=
analySisComment
(
htmlBody
,
url
);
List
<
TouTiaoComment
>
commentes
=
analySisComment
(
htmlBody
,
url
);
...
@@ -132,12 +130,12 @@ public class TouTiaoCommentParse {
...
@@ -132,12 +130,12 @@ public class TouTiaoCommentParse {
* @return int 返回类型
* @return int 返回类型
* @throws Exception
* @throws Exception
*/
*/
private
static
int
getPage
(
String
group_id
)
throws
Exception
private
static
int
getPage
(
String
group_id
,
Proxy
proxy
)
throws
Exception
{
{
String
urlNew
=
"http://www.toutiao.com/api/comment/list/?group_id="
+
group_id
+
"&item_id=0&count=20&offset=0"
;
String
urlNew
=
"http://www.toutiao.com/api/comment/list/?group_id="
+
group_id
+
"&item_id=0&count=20&offset=0"
;
//设置头信息
//设置头信息
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
null
,
headerMap
);
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
)
if
(
htmlBody
!=
null
)
{
{
...
@@ -174,7 +172,7 @@ public class TouTiaoCommentParse {
...
@@ -174,7 +172,7 @@ public class TouTiaoCommentParse {
try
{
try
{
//设置头信息
//设置头信息
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
String
htmlBody
=
HttpClientTemplateOK
.
get
(
url
,
null
,
headerMap
);
String
htmlBody
=
HttpClientTemplateOK
.
get
(
url
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
&&
htmlBody
.
contains
(
"commentInfo"
))
if
(
htmlBody
!=
null
&&
htmlBody
.
contains
(
"commentInfo"
))
{
{
try
{
try
{
...
@@ -205,7 +203,8 @@ public class TouTiaoCommentParse {
...
@@ -205,7 +203,8 @@ public class TouTiaoCommentParse {
{
{
try
{
try
{
//设置头信息
//设置头信息
String
htmlBody
=
HttpBoot
.
syncCall
(
RequestUtils
.
wrapGet
(
url
)).
body
().
string
();
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
String
htmlBody
=
HttpClientTemplateOK
.
get
(
url
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
&&
htmlBody
.
contains
(
"commentInfo"
))
if
(
htmlBody
!=
null
&&
htmlBody
.
contains
(
"commentInfo"
))
{
{
try
{
try
{
...
@@ -237,7 +236,7 @@ public class TouTiaoCommentParse {
...
@@ -237,7 +236,7 @@ public class TouTiaoCommentParse {
String
urlNew
=
"http://www.toutiao.com/api/comment/list/?group_id="
+
group_id
+
"&item_id=0&count=20&offset=0"
;
String
urlNew
=
"http://www.toutiao.com/api/comment/list/?group_id="
+
group_id
+
"&item_id=0&count=20&offset=0"
;
//设置头信息
//设置头信息
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
null
,
headerMap
);
String
htmlBody
=
HttpClientTemplateOK
.
get
(
urlNew
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
)
if
(
htmlBody
!=
null
)
{
{
...
...
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