日期:2014-05-20  浏览次数:20759 次

求教关于网络爬虫问题
我刚看《自己动手写网络爬虫》这本书, 照着书本敲了第一个程序, 可是编译通过了, 但是运行时说有异常, 小弟菜鸟, 实在看不懂,, 直接上代码了, HttpCient的jar包, 已经导入了。求大神看看


package TestURL;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.collections4.map.StaticBucketMap;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.omg.CORBA.PUBLIC_MEMBER;
public class RetrivePage {
private static HttpClient httpClient = new HttpClient();
static {
httpClient.getHostConfiguration().setProxy("172.17.8.18.84", 8080);
}

public static boolean downLoadPage (String path) throws HttpException, IOException{
InputStream input = null;
OutputStream output = null;
//得到post方法
PostMethod postMethod = new PostMethod(path);
//设置post方法的参数

NameValuePair[] postData = new NameValuePair[2];
postData[0] = new NameValuePair("name", "lietu");
postData[1] = new NameValuePair("password", "*****");
postMethod.addParameters(postData);
//执行, 返回状态码
int statusCode= httpClient.executeMethod(postMethod);
//针对状态码进行处理, 先是只处理返回值为200的状态码
if(statusCode == HttpStatus.SC_OK) {
input = postMethod.getResponseBodyAsStream();
//得到文件名
String filename = path.substring(path.lastIndexOf('/') + 1);
//获得文件输出流
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();
}
return true;
}
return false;
}
/*
 * 测试代码
 */
public static void main(String[] args) throws IOException {
//抓取首页, 输出
try {
RetrivePage.downLoadPage("http://www.lietu.com/");
}catch(HttpException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
}

下面是异常出现的地方
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more

谢谢啦
更多 0
------解决方案--------------------
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

日志包导入了吗