Commit 7c54baf9 by yangchen

添加微信量 获取

parent 5429fc24
package com.zhiwei.wechat.search;
import java.net.Proxy;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;
import com.zhiwei.crawler.core.HttpBoot;
import com.zhiwei.crawler.core.RequestUtils;
public class WechatCount {
private static HttpBoot httpBoot = new HttpBoot();
public static int getWechatCountByWord(String word, String cookie,
String startTime, String endTime, Proxy proxy) {
Map<String, String> headerMap = getWechatCount(cookie);
try {
String url = "http://weixin.sogou.com/weixin?type=2&ie=utf8&query="
+ URLEncoder.encode(word, "UTF-8") + "&tsn=5&ft="
+ startTime.split(" ")[0] + "&et=" + endTime.split(" ")[0]
+ "&interation=&wxid=&usip=";
headerMap.put("Referer", url);
String result = httpBoot
.syncCall(RequestUtils.wrapGet(url, headerMap), proxy)
.body().string();
String s = "";
int n = -1;
if (result.contains("找到约") && result.contains("条结果")) {
s = result.split("找到约")[1].split("条结果")[0];
n = Integer.valueOf(s.replaceAll(",", ""));
}
Elements elements = Jsoup.parse(result).select("ul.news-list")
.select("li");
if (n == -1) {
n = elements.size();
}
return n;
} catch (Exception e) {
return 0;
}
}
public static void main(String[] args) {
String cookie = "CXID=B4F6BF06873D2EFBC767B5EFF2747322; SUID=EAD6E7735E68860A5BF25BAB000EB028; SUV=0008470373E7D6EA5BF756F2BAF2D602; ABTEST=0|1543028023|v1; IPLOC=CN3302; weixinIndexVisited=1; ad=lFGL3Zllll2bDOmrlllllVZp2JyllllltMKQfkllllwlllllxp2PGK@@@@@@@@@@";
String startTime = "2018-08-01 00:00:00";
String endTime = "2018-08-02 00:00:00";
int c = getWechatCountByWord("唐嫣", cookie, startTime, endTime, null);
System.out.println(c);
}
private static Map<String, String> getWechatCount(String cookie) {
Map<String, String> headerMap = new HashMap<>();
headerMap.put("User-Agent",
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36");
headerMap.put("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
headerMap.put("Accept-Language", "zh-CN,zh;q=0.9");
headerMap.put("Connection", "keep-alive");
headerMap.put("Host", "weixin.sogou.com");
if (cookie != null) {
headerMap.put("Cookie", cookie);
}
return headerMap;
}
}
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