在学习使用httpclient抽取网页代码,可是抽取下来发现,为什么原网页上翻页的地方没有对应代码,如下:
原网页:抽取出的代码部分:使用浏览器审查元素,对应的代码:第一次使用httpclient,用java抽取网页。Java浏览器httpclient
原网页:抽取出的代码部分:使用浏览器审查元素,对应的代码:第一次使用httpclient,用java抽取网页。Java浏览器httpclient
解决方案 »
- 怎么做一个小的应用程序
- 大家看看这个tomcat报错什么原因,在线等
- ???我的两个前台统计程序部署到一个包里,用了同一个log4j.properties------>
- spring 整合 hibernate 使用泛型的异常
- hibernate多表映射中如何添加单个表的信息,有例!
- 请问当前有什么流行的用于WEB 界面的 JSP 标签库,请推荐几个
- 如何用jbuilder2005创建cmp2.0?
- 请教大家,这个想法如何实现?
- 急急急,请推荐基本Java开发Web Service的好书!
- 构建项目和重启web服务器的问题!
- hibernate一对多问题只在一方控制保存失败的问题
- request.getParameterMap().get("attachs");拿不到值
System.out.println("RetrivePage.downloadPage start");
InputStream input = null;
OutputStream output = null;
//得到post方法
// PostMethod postMethod = new PostMethod();
// //设置post方法的参数
// NameValuePair[] postData = new NameValuePair[2];
// postData[0] = new NameValuePair("name", "lietu");
// postData[1] = new NameValuePair("password", "*****");
// postMethod.addParameters(postData);
GetMethod getMethod = new GetMethod(path);
//执行,返回状态码
// int statusCode = httpClient.executeMethod(postMethod);
int statusCode = httpClient.executeMethod(getMethod);
System.out.println("statusCode:"+statusCode);
//针对状态码进行处理
if (statusCode == HttpStatus.SC_OK) {
// input = postMethod.getResponseBodyAsStream();
input = getMethod.getResponseBodyAsStream();
//得到文件名
// String filename = path.substring(path.lastIndexOf('/')+1);
String filename = "test.txt";
//获得文件输出流
output = new FileOutputStream(filename);
//输出到文件
int tempByte = -1;
while ((tempByte = input.read()) > 0) {
output.write(tempByte);
}
//关闭输入输出流
if (input!=null) {
input.close();
}
if (output!=null) {
output.close();
}
System.out.println("RetrivePage.downloadPage end");
return true;
}
return false;
}