nutch0.9实现抓取动态网页部署笔记

一:准备工作:

    1:下载nutch,地址是:http://www.apache.org/dist/lucene/nutch/

    2:下载JDK6(一定要是jdk6的版本,否则会报错),地址是:

http://java.sun.com/javase/downloads/index.jsp

     3:下载Cygwin(是一个在windows平台上运行的unix模拟环境的软件),地址是:http://www.cygwin.com/ 安装说明参考这里:     4:下载tomcat6,地址是:http://tomcat.apache.org/

二:配置:(前面的软件都安装完毕)

1:解压缩的nutch后,到conf下面修改crawl-urlfilter.txt

#accepthostsinMY.DOMAIN.NAME

+^http://([a-z0-9]*\.)*apache.org/

+^http://([a-z0-9]*\.)*longtask.com/blog/

如果有需要可以继续添加相关的站点.

2:修改conf下面的nutch-site.xml文件,在<configuration>之间添加以下内容

<property>

<name>http.agent.name</name>

<value>longtask</value>

<description>HTTP‘User-Agent’requestheader.</description>

</property>

<property>

<name>http.agent.description</name>

<value>longtask</value>

<description>Furtherdescriptionofourbot-thistextisusedintheUser-Agentheader.

</description>

</property>

<property>

<name>http.agent.url</name>

<value>http://www.longtask.com/blog/</value>

<description>AURLtoadvertiseintheUser-Agentheader.

</description>

</property>

<property>

<name>http.agent.email</name>

<value>longtask@gmail.com</value>

<description>AnemailaddresstoadvertiseintheHTTP‘From’requesheaderandUser-Agentheader.

</description>

</property>

     3:回到到nutch的根目录,进入bin目录,建一个urls的文件夹,在文件夹中建一个nutch.txt的问题件,在文件中加入上面要鉴权的Url地址(抓取的网址(nutch.txt)经过(crawl-urlfilters.xml)过滤后,如果没有内容会在log中报错:Stopping at depth=0 – no more URLs to fetch.)。这个地方用nutch1.0怎么都跑不过,只能换回0.9的版本了。

三:解决搜索动态内容的问题:

需要注意在conf下面的2个文件:regex-urlfilter.txt,crawl-urlfilter.txt

#skipURLscontainingcertaincharactersasprobablequeries,etc.

-[?*!@=](-改+)

这段意思是跳过在连接中存在?*!@=的页面,因为默认是跳过所以,在动态页中存在?一般按照默认的是不能抓取到的。可以在上面2个文件中都修改成:

#skipURLscontainingcertaincharactersasprobablequeries,etc.

#-[?*!@=]

另外增加允许的一行

#acceptURLscontainingcertaincharactersasprobablequeries,etc.

+[?=&]

意思是抓取时候允许抓取连接中带?=&这三个符号的连接

     注意:两个文件都需要修改,因为NUTCH加载规则的顺序是crawl-urlfilter.txt-> regex-urlfilter.txt

四:运行爬虫,抓取内容:

打开Cygwin,

在命令行窗口中输入:cdnutch的目录/bin

执行命令:

shnutchcrawlurls-dire:/index-depth3-threads4-topN50>&./log.txt

说明:

-dirdirnames设置保存所抓取网页的目录.

-depthdepth表明抓取网页的层次深度

-delaydelay表明访问不同主机的延时,单位为“秒”

-threadsthreads表明需要启动的线程数

-topNnumber在每次迭代中限制爬行的头几个链接数,默认是Integer.MAX_VALUE

运行结束后,查看log.txt日志,会有爬虫检索网页的详细信息。

问题的解决:运行的过程中报错:

Stoppingatdepth=0–nomoreURLstofetch.

NoURLstofetch–checkyourseedlistandURLfilters.

在urls的nutch.txt中再添加一个URL即可,这个是nutch0.9的bug(如果是1.0这个地方不知道怎么搞定,所以改回0.9来部署了。)

五:部署到tomcat下面:

1:配置nutch-0.9.war包中的文件

a:修改nutch-0.9.war\WEB-INF\web.xml

<?xmlversion="1.0"encoding="ISO-8859-1"?>

<?xmlversion="1.0"encoding="UTF-8"?>

b:修改nutch-0.9.war\WEB-INF\class\nutch-site.xml

注意:不要让你的config中有2个<configuration>,否则的话检索不出来东西。

<configuration>

<property>

<name>searcher.dir</name>

<value>e:/index</value>

</property>

</configuration>

     2:把应用部署到tomcat的webapps下面,启动tomcat,访问应用:http://localhost:8080/nutch-0.9就可以得到以下界面:

    nutch0.9实现抓取动态网页部署笔记 输入访问的条件后,结果如下:

nutch0.9实现抓取动态网页部署笔记

相关推荐