`

Nutch抓取需要登录的网站

阅读更多

Tomcat自身带的后台管理程序是需要用户登录的,这样的网站如何用Nutch来爬呢?Nutch可以处理Http authentication(BASIC, DIGEST)这种稍显简单的认证,对于普遍流行的用户自定义Form表单以Post或Get方式提交数据认证的情况,Nutch就无能为力了,就更不用说复杂验证码的认证方式了。

 

下面用一个简单的例子说明如何配置Nutch,使其能爬需要Http authentication(BASIC, DIGEST)的站点。

 

1、修改Tomcat配置文件conf/tomcat-users.xml,增加如下配置然后重启,一个用户即可访问所有资源:

 

<role rolename="admin-script"/>
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user password="admin" roles="admin-script,admin-gui,manager-script,manager-gui,manager-jmx,manager-status" username="admin"/>

 

2、修改Nutch配置文件conf/httpclient-auth.xml,增加如下配置,指定访问特定网站的时候需要出示的用户名和密码:

 

<credentials username="admin" password="admin">
  <authscope host="localhost" port="8080"/>
</credentials>

 

3、启用httpclient插件,在nutch-site.xml中重新指定配置项plugin.includes的值,把protocol-http改为protocol-httpclient:

 

<property>
  <name>plugin.includes</name>
  <value>protocol-httpclient|urlfilter-regex|parse-(html|tika)|index-(basic|anchor)|indexer-solr|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
</property>

 

4、准备注入的URL文件:

 

mkdir urls  
echo 'http://localhost:8080/' > urls/url  

 

5、修改URL过滤文件conf/regex-urlfilter.txt限制抓取范围:

 

#-[?*!@=]
+^http://localhost:8080/
-.

 

6、运行爬虫,参数为:

 

bin/nutch crawl urls -dir data -solr http://localhost:8983/solr/collection1 -depth 30 & 

 

7、查看抓取下来的URL及其状态发现,成功!

 

NUTCH/HADOOP视频教程

1
3
分享到:
评论
2 楼 yangshangchuan 2014-08-22  
niubingru 写道
请问如何访问一般的需要登录的网站,比如新浪微博,人人网什么的


用户自定义Form表单以Post或Get方式提交数据认证的情况,Nutch就无能为力了,所以需要自己来实现,虽然不同的网站的情况不一样,但是还是可以设计一个通用的模式:
1、登录的时候验证提交数据的地址;
2、以POST或GET方式提交哪些数据;
3、发送哪些COOKIES;
4、如何指定HTTP请求头信息。
1 楼 niubingru 2014-08-01  
请问如何访问一般的需要登录的网站,比如新浪微博,人人网什么的

相关推荐

Global site tag (gtag.js) - Google Analytics