nutch如何才能抓取到动态的url,配置文件解析

在运行的时候不会抓取到,分析了一下原因:主要在conf/crawl-urlfilter.txt.
分析:使用nutch默认的配置过滤文件的话,是不抓取到包含?*!@=等字符的URL
解决办法:修改crawl-urlfilter的过滤规则,

# The url filter file used by the crawl command.

# Better for intranet crawling.
# Be sure to change MY.DOMAIN.NAME to your domain name.

# Each non-comment, non-blank line contains a regular expression
# prefixed by '+' or '-'. The first matching pattern in the file
# determines whether a URL is included or ignored. If no pattern
# matches, the URL is ignored.

# skip file:, ftp:, & mailto: urls
-^(file|ftp|mailto):

# skip image and other suffixes we can't yet parse
-/.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$

# skip URLs containing certain characters as probable queries, etc.
-[?*!@=]   //表示过滤包含指定字符的URL,改为: -[~]

# skip URLs with slash-delimited segment that repeats 3+ times, to break loops
-.*(/.+?)/.*?/1/.*?/1/

# accept hosts in MY.DOMAIN.NAME
+^http://([a-z0-9]*/.)*tianya.cn/[/s/S]*    // 过滤正则表达式,([a-z0-9]*/.)*表示任意数字和字母,[/s/S]*表示任意字符
# skip everything else
-.


Nutch爬虫设置
Nutch本身包含一个对目标站点进行索引的爬虫和一个提供搜索用的web界面。在查询界面可以使用前需要先设置Nutch爬虫对目标站点进行抓取。
部分配置文件的解释:
nutch/conf/nutch-default.xml
          设置http.agent.name,如果http.agent.name为空,爬虫将无法正常启动。这里可以设置任意你喜欢的名字,比如设置为vik-robot。
          indexer.mergeFactor/indexer.minMergeDocs 这两个值都改成500。这两个参数值越大,性能越高,所需要花费的内存也需要相应的增加。如果设置过大,可能出现内存溢出。就实际使用情况,在当前参数下,内存的最大使用量为3xxM。
          http.timeout表示最大超时等待时间,如果访问的连接长时间没有反应将丢弃。
          db.max.outlinks.per.page该参数表示单个页面最多支持多少个外连的连接,如果过多将不抓取。 如果是自己的内部系统那就设置一个任意大的数吧。

 

nutch/conf/crawl-urlfilter.txt

该文件用于设置需要索引的url的过滤关系。每行一个过滤条件,-表示不包含该url,+表示包含。
          [?*!@=],该行表示对所有动态url都不抓取。 现在的大部分系统都会有很多动态url,该过滤条件很可能使你抓不到任何内容。
           针对各系统分别设置url的过滤关系。具体的设置方法得根据各自应用系统的不同而不同,这里以广为流行的论坛discuz为例。在这url过滤将只抓取板块列表和帖子内容。

            # skip file:, ftp:, & mailto: urls
            -^(file|ftp|mailto):

            # skip image and other suffixes we can't yet parse
            -/.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|MOV|exe|jpeg|JPEG|bmp|BMP)$

            # skip URLs containing certain characters as probable queries, etc.
            #-[?*!@=]

            # skip URLs with slash-delimited segment that repeats 3+ times, to break loops
            -.*(/.+?)/.*?/1/.*?/1/

            # accept hosts in MY.DOMAIN.NAME
            #+^http://([a-z0-9]*/.)*MY.DOMAIN.NAME/
            #discuz
            +^http://mysite.com/discuz/index.php$
            +^http://mysite.com/discuz/forumdisplay.php/?fid=/d+$
            +^http://mysite.com/discuz/forumdisplay.php/?fid=/d+&page=/d+$
            +^http://mysite.com/discuz/viewthread.php/?tid=/d+&extra=page%3D/d+$
            +^http://mysite.com/discuz/viewthread.php/?tid=/d+&extra=page%3D/d+&page=/d+$
            # skip everything else
            -.

nutch/conf/regex-urlfilter.txt

我不清楚该配置文件是否有起作用,但建议注释掉其中的,-[?*!@=]。

你可能感兴趣的:(nutch如何才能抓取到动态的url,配置文件解析)