关于使用httpclient抽取网页代码的简单问题 在学习使用httpclient抽取网页代码,可是抽取下来发现,为什么原网页上翻页的地方没有对应代码,如下:原网页:抽取出的代码部分:使用浏览器审查元素,对应的代码:第一次使用httpclient,用java抽取网页。Java浏览器httpclient 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 抽取网页的源码:public static boolean downloadPage (String path) throws HTTPException, IOException { 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; } 新浪的端链接怎么实现的 今天面试题 请教struts2 ajax 请问各位高手有上传下载的例子不 求助:关于spring中aop的问题 调用外网接口的问题 为汶川人民祈福 关于struts中的几个<html标签问题 疑难问题,servlet运行过程中的怪异现象 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;
}