public static void trustEveryone() {
try {
HttpsURLConnection
.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname,
SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}

public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context
.getSocketFactory());
} catch (Exception e) {
// e.printStackTrace();
}
}


/**
* @param good_url 商品URl
* @return 返回值是商品的评价数量
*/
public static String getEv_num(String good_url){
try {

String id=good_url.split("/")[6].split(".html")[0];
String url="http://www.sfbest.com/comments/ajaxPl/";
URL baseurl = new URL(url);
trustEveryone();
org.jsoup.Connection conn = HttpConnection.connect(baseurl);
conn.timeout(10000);
conn.header("accept", "application/json, text/javascript, */*; q=0.01");
conn.header("Accept-Encoding", "gzip, deflate");
conn.header("Accept-Language", "zh-CN,zh;q=0.8");
conn.header("connection", "Keep-Alive");
conn.header("Content-Length", "35");
conn.header("Content-Type", "application/x-www-form-urlencoded");
conn.header("Cookie","siteid=SF_CURRENT_SITE; provinceid=2; cityid=52; areaid=500; " +
"townid=0; bdshare_firstime=1516961354705; _SF_USER_HASH_=a86c5eca7ca4db3e; " +
"_SF_AUTH_HASH_=4ddeb3771b7991c3; _ems_visitor=1417598425.329643289;" +
" _da_z=24490488.1517799775.5.2.ccn=(referral)|csr=sfbest.com|cct=/html/products/244/1300243033.html|cmd=referral; " +
"__xsptplus130=130.2.1517799883.1517800202.4%234%7C%7C%7C%7C%7C%23%23-ts5ran1n4TdkcvHp5-Y6QZKQeUDDbjr%23;" +
" _da_a=24490488.20180126180902624745.1516961343.1517799775.1517810037.6;" +
" __utma=24490488.1119885806.1517465621.1517796317.1517812872.3; " +
"__utmb=24490488.4.9.1517813131564; __utmc=24490488; " +
"__utmz=24490488.1517465621.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);" +
" _ems_session=1417598425.561290200;" +
" _sf_tj_cc=ymfz0gxvaau1516961342392.1516961342.1517799774.1517810036.6.13.1517813531; " +
"Hm_lvt_cceda50ef06cbaf44bdeaabe2470efee=1516961342,1517394409,1517794523;" +
" Hm_lpvt_cceda50ef06cbaf44bdeaabe2470efee=1517813531;" +
" history=a%3A10%3A%7Bi%3A0%3Bi%3A251937%3Bi%3A1%3Bi%3A257431%3Bi%3A2%3Bi%3A58179%3Bi%3A3%3Bi%3A264699%3Bi%3A4%3Bi%3A264575%3Bi%3A5%3Bi%3A233885%3Bi%3A6%3Bi%3A271517%3Bi%3A7%3Bi%3A245643%3Bi%3A8%3Bi%3A279119%3Bi%3A9%3Bi%3A279811%3B%7D; " +
"_da_b=24490488.13.10.1517810037;" +
"Hm_lvt_56b4bab8080250772f08703b41839413=1516961340,1517394409,1517794521;" +
"Hm_lpvt_56b4bab8080250772f08703b41839413="+new Date().getTime());
conn.header("Host","www.sfbest.com");
conn.header("Origin","http://www.sfbest.com");
conn.header("Referer",good_url);
conn.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
conn.header("X-Requested-With", "XMLHttpRequest");
conn.data("pid","282387");
conn.data("page","1");
conn.data("pageNum","10");
conn.data("type","0");
conn.ignoreContentType(true);
//conn.execute();
Document parse = conn.post();
Thread.sleep(1000);
String str=parse.text();
System.err.println(id);
System.err.println(str);
System.err.println(new Date().getTime());
return null;
} catch (Exception e) {
// TODO: handle e xception
}
return null;
}
public static void main(String[] args) {
String url="http://www.sfbest.com/comments/ajaxPl/";
String param="http://www.sfbest.com/html/products/280/4200279811.html";
try {
System.out.println(getEv_num(param));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}