private static void func_httpGet(String url) { HttpClient httpClient = new HttpClient(); try { GetMethod getMethod = new GetMethod(url); getMethod.getParams().setContentCharset("uft-8"); getMethod.setRequestHeader("Accept-Encoding", "uft-8,deflate, sdch"); getMethod.setRequestHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); getMethod.setRequestHeader("Referer","http://www.0597kk.com/thread.php?fid=2"); getMethod.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8"); getMethod.setRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) QQBrowser/9.2.5063.400"); int statusCode = httpClient.executeMethod(getMethod);// 返回状态码200为成功,500为服务器端发生运行错误 // System.out.println("返回状态码:" + statusCode); // 打印出返回数据,检验一下是否成功 InputStream inputStream = getMethod.getResponseBodyAsStream(); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); StringBuffer stringBuffer = new StringBuffer(); String str = ""; while ((str = br.readLine()) != null) { stringBuffer.append(str); } if (statusCode == 200) { Document doc = Jsoup.parse(stringBuffer.toString()); Elements num = doc.select("div[class=readNum]").select("ul[class=cc]").select("em"); try { System.out.println("当前阅读量:"+num.get(0).text()); } catch (Exception e) { // TODO: handle exception System.err.println("获取阅读量失败!"); } } } catch (Exception e) { e.printStackTrace(); } }