Commit c6199334 by zhiwei

知乎添加移動端的榜單採集

parent af14ca7b
......@@ -73,4 +73,58 @@ public class ZhihuHotSearchCrawler {
}
return list;
}
/**
* @Title: getMobileZhihuHotList
* @author hero
* @Description: 移動端知乎熱搜榜
* @param @return 设定文件
* @return List<ZhihuHotSearch> 返回类型
*/
public static List<ZhihuHotSearch> getMobileZhihuHotList(){
List<ZhihuHotSearch> list = null;
String url = "https://api.zhihu.com/topstory/hot-list?limit=40&reverse_order=0";
Map<String,String> headerMap = HeaderTool.getCommonHead();
headerMap.put("Host", "api.zhihu.com");
headerMap.put("Referer", url);
headerMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36");
headerMap.put("X-UDID", "AFAC3hv3vgyPTt9ZmNmqTm0yv_8NKY3S3z8=");
headerMap.put("authorization", "oauth c3cef7c66a1843f8b3a9e6a1e3160e20");
for(int j=0;j<3;j++){
try {
System.out.println(url);
String htmlBody = HttpClientTemplateOK.get(url, null, headerMap);
System.out.println(htmlBody);
if(htmlBody != null){
if(htmlBody.contains("author")){
list = new ArrayList<ZhihuHotSearch>();
JSONObject top_search = JSONObject.parseObject(htmlBody);
JSONArray words = top_search.getJSONArray("data");
String link = null;
String display_query = null;
String query = null;
for (int i = 0; i < words.size(); i++) {
JSONObject word = words.getJSONObject(i).getJSONObject("target");
query = word.getString("title");
display_query = word.getString("title");
link = "https://www.zhihu.com/question/"+word.getLongValue("id");
ZhihuHotSearch zhihu = new ZhihuHotSearch(link, query, display_query,new Date());
System.out.println(zhihu);
list.add(zhihu);
}
break;
}else{
System.out.println("---------------");
}
}
} catch (IOException e) {
logger.debug("获取知乎热搜时出现问题:{}", e.fillInStackTrace());
continue;
}
}
return list;
}
}
......@@ -16,7 +16,7 @@ public class HotSearchRun {
private ScheduledExecutorService scheduExec;
public HotSearchRun() {
this.scheduExec = Executors.newScheduledThreadPool(4);
this.scheduExec = Executors.newScheduledThreadPool(1);
}
public void showTimer() {
......
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