大虾们,求帮助……用httpclient 进行获取微信搜狗公众号文章问题,
http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFtyoPnoKxqvND4ufXLQ-4SRc&page=1该地址如频繁调用微信搜狗会限制查询,返回的结果不对,求指导……
http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFtyoPnoKxqvND4ufXLQ-4SRc&page=1该地址如频繁调用微信搜狗会限制查询,返回的结果不对,求指导……
try { HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet("http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFtyoPnoKxqvND4ufXLQ-4SRc&page=1"); StringBuffer strBuf = new StringBuffer(); HttpResponse response = client.execute(httpGet); if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { HttpEntity entity = response.getEntity(); if (entity != null) { BufferedReader reader = new BufferedReader( new InputStreamReader(entity.getContent(), "UTF-8")); String line = null; if (entity.getContentLength() > 0) { strBuf = new StringBuffer((int) entity.getContentLength()); while ((line = reader.readLine()) != null) { strBuf.append(line); } } } if (entity != null) { entity.consumeContent(); } } System.out.println(strBuf.toString()); } catch (Throwable t) { System.out.println(t.toString()); t.printStackTrace(); }
访问频繁后连接会返回如下结果:并不是文章信息。
charset=ISO-8859-1 HttpMethodBase - Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. <html> <head> <script> var uri = document.location.href; var pos = uri.indexOf("?"); if(pos!=-1)uri = uri.substr(0,pos); var domain = ".sogou.com"; if(uri.indexOf("soso.com")>-1)domain = ".soso.com"; var date = new Date(); if(document.cookie.indexOf("SUV=")<0) document.cookie="SUV="+(date.getTime())*1000+Math.round(Math.random()*1000)+";path=/;expires=Sun, 29 July 2046 00:00:00 UTC;domain="+domain; date.setTime(date.getTime()+5*24*3600*1000);//2tian document.cookie = "SNUID=25489A3D898F9BD9987AC9D68A8B356D; path=/; expires="+date.toGMTString(); document.location.href = "/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFtyoPnoKxqvND4ufXLQ-4SRc&page=1&t=1427522889323&repp=1"; </script> </head> </html><!--zly-->
解决方案