|
什么是网络爬虫
网络爬虫
(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动的抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁,自动索引,模拟程序或者蠕虫。
网络爬虫
是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成。传统爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL,在抓取网页的过程中,不断从当前页面上抽取新的URL放入队列,直到满足系统的一定停止条件。
随着网络的迅速发展,万维网成为大量信息的载体,如何有效地提取并利用这些信息成为一个巨大的挑战。搜索引擎(Search Engine),例如传统的通用搜索引擎AltaVista,Yahoo!和Google等,作为一个辅助人们检索信息的工具成为用户访问万维网的入口和指南。但是,这些通用性搜索引擎也存在着一定的局限性
就是捉取和搜集网络数据。
它可以模拟客户端请求,登录权限的模拟,然后捉取数据。-->进行分析!
简单爬虫
public static String getContentByUrl(String url) throws Exception{
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(url);
setHead(get);
int state = client.executeMethod(get);
if (200 == state) {
return (new String(get.getResponseBodyAsString().getBytes("iso-8859-1"),"utf-8"));
}else{
return null;
}
}
public static HttpMethodBase setHead(HttpMethodBase get){
get.addRequestHeader("Host", "www.baidu.com");
get.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0");
get.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
get.addRequestHeader("Accept-Language", "zh-cn,zh;q=0.5");
//get.addRequestHeader("Accept-Encoding", "gzip, deflate");
get.addRequestHeader("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");
get.addRequestHeader("Connection", "keep-alive");
get.addRequestHeader("Referer", "http://www.baidu.com/member/login");
get.addRequestHeader("Cookie", "PHPSESSID=195cb3ecdf2eb2e5ef694a922bb478e3; Hm_lvt_bc97aabf99434efa3940a5886150c7e7=1323657227055; Hm_lpvt_bc97aabf99434efa3940a5886150c7e7=1323657251442; local[ip]=61.148.82.174; local[uid]=294; local[is]=y");
return get;
}
public static void main(String[] args) throws Exception {
getContentByUrl("http://www.baidu.com/member/login");
}
|
|
|