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
60f6bcc2
Commit
60f6bcc2
authored
Oct 28, 2019
by
zhiwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加更新今日头条阅读数功能
parent
c692ae5b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
55 deletions
+47
-55
src/main/java/com/zhiwei/toutiao/parse/TouTiaoArticleParse.java
+10
-3
src/test/java/com/zhiwei/toutiao/test/TouTiaoCommentExample.java
+37
-52
No files found.
src/main/java/com/zhiwei/toutiao/parse/TouTiaoArticleParse.java
View file @
60f6bcc2
...
@@ -661,15 +661,22 @@ public class TouTiaoArticleParse {
...
@@ -661,15 +661,22 @@ public class TouTiaoArticleParse {
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
Map
<
String
,
String
>
headerMap
=
Tools
.
getTouTiaoHeader
();
headerMap
.
put
(
"Referer"
,
"https://m.toutiao.com/i"
+
itemId
+
"/"
);
headerMap
.
put
(
"Referer"
,
"https://m.toutiao.com/i"
+
itemId
+
"/"
);
headerMap
.
put
(
"User-Agent"
,
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Mobile Safari/537.36"
);
headerMap
.
put
(
"User-Agent"
,
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Mobile Safari/537.36"
);
headerMap
.
put
(
"Host"
,
"m.toutiao.com"
);
headerMap
.
put
(
"Sec-Fetch-Mode"
,
"navigate"
);
headerMap
.
put
(
"Sec-Fetch-Site"
,
"none"
);
headerMap
.
put
(
"Sec-Fetch-User"
,
"?1"
);
headerMap
.
put
(
"Upgrade-Insecure-Requests"
,
"1"
);
String
htmlBody
=
downloadHtml
(
urlNew
,
proxy
,
headerMap
);
String
htmlBody
=
downloadHtml
(
urlNew
,
proxy
,
headerMap
);
if
(
htmlBody
!=
null
)
if
(
StringUtils
.
isNotBlank
(
htmlBody
)
&&
htmlBody
.
contains
(
"impression_count"
)
)
{
{
try
{
try
{
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
JSONObject
data
=
JSONObject
.
parseObject
(
htmlBody
).
getJSONObject
(
"data"
);
String
commentNum
=
data
.
getInteger
(
"comment_count"
).
toString
();
String
commentNum
=
data
.
getInteger
(
"comment_count"
).
toString
();
String
readNum
=
data
.
getInteger
(
"impression_count"
).
toString
();
String
readNum
=
data
.
getInteger
(
"impression_count"
).
toString
();
String
playCount
=
data
.
getInteger
(
"video_play_count"
).
toString
();
String
playCount
=
"0"
;
if
(
data
.
containsKey
(
"video_play_count"
)
&&
data
.
getInteger
(
"video_play_count"
)>=
0
){
playCount
=
data
.
getInteger
(
"video_play_count"
).
toString
();
}
String
userId
=
data
.
getJSONObject
(
"media_user"
).
getLong
(
"id"
).
toString
();
String
userId
=
data
.
getJSONObject
(
"media_user"
).
getLong
(
"id"
).
toString
();
String
source
=
data
.
getString
(
"source"
);
String
source
=
data
.
getString
(
"source"
);
String
title
=
data
.
getString
(
"title"
);
String
title
=
data
.
getString
(
"title"
);
...
...
src/test/java/com/zhiwei/toutiao/test/TouTiaoCommentExample.java
View file @
60f6bcc2
//package com.zhiwei.toutiao.test;
package
com
.
zhiwei
.
toutiao
.
test
;
//
//import java.net.InetSocketAddress;
import
java.net.InetSocketAddress
;
//import java.net.Proxy;
import
java.net.Proxy
;
//import java.net.Proxy.Type;
import
java.net.Proxy.Type
;
//import java.util.ArrayList;
import
java.util.ArrayList
;
//import java.util.List;
import
java.util.List
;
//
//import com.zhiwei.toutiao.bean.TouTiaoComment;
import
com.zhiwei.toutiao.bean.TouTiaoArticle
;
//import com.zhiwei.toutiao.parse.TouTiaoCommentParse;
import
com.zhiwei.toutiao.bean.TouTiaoComment
;
//
import
com.zhiwei.toutiao.parse.TouTiaoArticleParse
;
///**
import
com.zhiwei.toutiao.parse.TouTiaoCommentParse
;
// * @ClassName: TouTiaoCommentExample
// * @Description: TODO(今日头条评论测试)
/**
// * @author hero
* @ClassName: TouTiaoCommentExample
// * @date 2016年12月9日 下午8:08:02
* @Description: TODO(今日头条评论测试)
// */
* @author hero
//public class TouTiaoCommentExample {
* @date 2016年12月9日 下午8:08:02
// private static String hostname = "192.168.9.37";
*/
// private static int host = 31128;
public
class
TouTiaoCommentExample
{
// private static Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(hostname, host));
//
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// public static void main(String[] args) throws Exception {
//
// TouTiaoCommentParse touTiaoComment = new TouTiaoCommentParse();
List
<
String
>
mids
=
new
ArrayList
<
String
>();
//
mids
.
add
(
"https://www.toutiao.com/a6549289895376978436/"
);
// List<String> mids = new ArrayList<String>();
// mids.add("https://www.toutiao.com/a6549289895376978436/");
for
(
String
mid
:
mids
)
//
{
// for(String mid : mids)
TouTiaoArticle
touTiaoArticle
=
TouTiaoArticleParse
.
getToutiaoArticleInfoByUrl
(
mid
,
null
);
// {
System
.
out
.
println
(
touTiaoArticle
);
// List<TouTiaoComment> list = touTiaoComment.getTouTiaoComment(mid, null);
}
// System.out.println(mid+"============="+list.size());
// for(TouTiaoComment ttc : list)
}
// {
// System.out.println(ttc);
//// DBObject doc = new BasicDBObject();
}
//// doc.put("_id", ttc.getId());
//// doc.put("text", ttc.getText());
//// doc.put("time", ttc.getTime());
//// doc.put("username", ttc.getUserName());
//// doc.put("reply_count", ttc.getReply_count());
//// doc.put("digg_count", ttc.getDigg_count());
//// doc.put("source_url", ttc.getId());
//// touTiaoCommentDAO.addTouTiaoComment(doc);
// }
// }
//
// }
//
//
//}
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