HttpGet
2024-08-27 04:34:13
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();
}
}
最新文章
- 在centos上配置IP
- smarty string_format用法 取小数点后2位
- [Math] Deferred Acceptance Algorithm
- intanceof以及引出的__proto__和prototype
- OOP三个基本特征:封装、继承、多态
- oracle数据操纵语言(DML)data manipulation language(续集)
- 关于Java中return和finally谁先执行.
- 阻塞式和非阻塞式IO
- C# 将窗口移动到指定位置
- mysql union ,UNION RESULT
- BZOJ:1185: [HNOI2007]最小矩形覆盖
- 使用DDL触发器同步多个数据库结构
- Server:www121 Server:www120 Server:NWS_SP
- topcoder srm 693 div1 -3
- Storm 简单介绍
- xfs参数简介
- php文章tag标签的增删
- NHibernate参考文档、下载地址
- try catch finally 与continue的使用
- Java Json API:Gson使用简单入门