Commit f19fd0ee by yangchen

知乎 专栏 点赞数 评论数采集添加

parent c4e67a9e
...@@ -142,11 +142,41 @@ public class ZhihuCrawlerParse { ...@@ -142,11 +142,41 @@ public class ZhihuCrawlerParse {
return null; return null;
} }
// public static void main(String[] args) { public static void main(String[] args) {
// String url = "68781862"; String url = "https://zhuanlan.zhihu.com/p/31577152";
// ZhihuQuestionData zqd = ZhihuCrawlerParse.getQuestionData(url, null); ZhiHuData zqd = ZhihuCrawlerParse.getUrlData(url, null);
// System.out.println(zqd.toString()); System.out.println(zqd.toString());
// } }
/**
*
* @Description 知乎专栏获取点赞评论数
* @param url
* @param proxy
* @return
*/
public static ZhiHuData getUrlData(String url,Proxy proxy) {
try (Response response = httpBoot.syncCall(RequestUtils.wrapGet(url), proxy)){
String result = response.body().string();
if(result.contains("initialState")) {
String jsonData = "{\"initialState" + result.split("initialState")[1].split("\\</script\\>")[0];
JSONObject json = JSONObject.parseObject(jsonData);
JSONObject jdata = json.getJSONObject("initialState").getJSONObject("entities")
.getJSONObject("articles").getJSONObject(url.split("p/")[1].split("\\?")[0]);
if(Objects.nonNull(jdata)) {
ZhiHuData zd = new ZhiHuData();
zd.setTitle(jdata.getString("title"));
zd.setComment_count(jdata.getInteger("commentCount"));
zd.setAttitudes_count(jdata.getInteger("voteupCount"));
zd.setUrl(url);
return zd;
}
}
} catch (Exception e) {
logger.error(" 知乎专栏获取 文章数据出错 {} ", e);
}
return null;
}
/** /**
* 根据关键词获取链接地址(栏目msg,问答question) * 根据关键词获取链接地址(栏目msg,问答question)
......
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