Commit 60f6bcc2 by zhiwei

添加更新今日头条阅读数功能

parent c692ae5b
...@@ -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");
......
//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);
// }
// }
//
// }
//
//
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment