【问题标题】:How to make nutch crawl files and subfolders - it only crawls the index of the folder如何使 nutch 抓取文件和子文件夹 - 它只抓取文件夹的索引
【发布时间】:2014-01-17 11:54:53
【问题描述】:

编辑:我找到了我的答案并写在下面,但赏金给了 tahagh,因为他提供了一些很好的建议。


我正在设置 nutch 来抓取本地文件夹(samba 挂载)。我遵循了this 教程。

我的文件夹如下所示:

nutch@ubuntu:~$ ls /mnt/ntserver/
expansion.docx  test-folder  test-shared.txt

test-folder 下面还有一些文件和文件夹。

当我运行 nutch 时,它不会索引文件或子文件夹。它只将单个文档放入 solr,即文件夹的索引。这是我在空 solr 索引上运行 nutch 后在 solr 中得到的结果:

"response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "content": [
          "Index of /mnt/ntserver Index of /mnt/ntserver ../ - - - expansion.docx Mon, 30 Dec 2013 14:00:42 GMT 70524 test-folder/ Fri, 17 Jan 2014 09:38:50 GMT - test-shared.txt Thu, 16 Jan 2014 11:33:42 GMT 16"
        ],
      .....

如何让 nutch 索引文件和子文件夹?


编辑:如果我将 regex-urlfilter 设置为允许像 +. 这样的所有内容(在过滤 gif、http 等之后),那么 nutch 似乎会上升文件夹层次结构,但不会下降,并且仍然只抓取索引,不是文件。这是我在 solr 中得到的:

"response": {
    "numFound": 26,
    "start": 0,
    "docs": [
      {
        "title": [
          "Index of /"
        ]
      },
      {
        "title": [
          "Index of /bin"
        ]
      },
      ...
      {
        "title": [
          "Index of /mnt"
        ]
      },
      {
        "title": [
          "Index of /mnt/ntserver"
        ]
      },
      ...
    ]

附加信息:

这是我使用的爬取命令:

apache-nutch-1.7/bin/nutch crawl -dir fileCrawl -urls apache-nutch-1.7/urls/ -solr http://localhost:8983/solr -depth 3 -topN 10000

这是我的种子网址文件的内容:

nutch@ubuntu:~$ cat apache-nutch-1.7/urls/urls_to_be_crawled.txt 
file:////mnt/ntserver

这是我的 regex-urlfilter.xml:

nutch@ubuntu:~$ cat apache-nutch-1.7/conf/regex-urlfilter.txt
# skip http: ftp: and mailto: urls
-^(http|ftp|mailto):

# skip image and other suffixes we can't yet parse
# for a more extensive coverage use the urlfilter-suffix plugin
-\.(gif|GIF|jpg|JPG|png|PNG|ico|ICO|css|CSS|sit|SIT|eps|EPS|wmf|WMF|zip|ZIP|ppt|PPT|mpg|MPG|gz|GZ|rpm|RPM|tgz|TGZ|mov|MOV|exe|EXE|jpeg|JPEG|bmp|BMP|js|JS|asp|ASP|xxx|XXX|yyy|YYY|cs|CS|dll|DLL|refresh|REFRESH)$

# accept any files
+.*mnt/ntserver.*

我已经包含protocol-file 并且在 nutch-site.xml 中对文件大小没有设置限制:

nutch@ubuntu:~$ cat apache-nutch-1.7/conf/nutch-site.xml
...
<property>
    <name>plugin.includes</name>
    <value>protocol-file|urlfilter-regex|parse-(html|tika|text)|index-(basic|anchor)|indexer-solr|scoring-opic|urlnormalizer-(pass|regex|basic)|index-more<!--|remove-empty-document|title-adder--></value>
    <description></description>
</property>

<property>
    <name>file.content.limit</name>
    <value>-1</value>
    <description> Needed to stop buffer overflow errors - Unable to read.....</description>
</property>

...

并且我已经注释掉了 regex-normalize.xml 中的重复斜线删除:

nutch@ubuntu:~$ cat apache-nutch-1.7/conf/regex-normalize.xml
...
<!-- removes duplicate slashes - commented out, so we won't get invalid filenames 
<regex>
    <pattern>(?&lt;!:)/{2,}</pattern>
    <substitution>/</substitution>
</regex>
-->
...

【问题讨论】:

    标签: regex solr nutch web-crawler


    【解决方案1】:

    调查 File 和 FileResponse 来源,我发现了以下内容:

    1. 有一个名为“file.crawl.parent”的配置参数控制 nutch 是否也应该爬取目录的父目录。默认情况下为真。
    2. 在这个实现中,当 nutch 遇到一个目录时,它会生成其中的文件列表作为内容中的一组超链接,否则它会读取文件内容。 Nutch 使用 File.isDirectory() 来确定给定路径是否为目录。因此,请检查您的路径是否真的被解释为目录。

    【讨论】:

      【解决方案2】:

      我发现为了爬取本地文件系统,你必须在种子 url 的末尾添加斜杠,否则 nutch 不会将路径的最后部分识别为目录。

      所以我改变了我的种子网址

      file:////mnt/ntserver
      

      file:////mnt/ntserver/
      

      然后事情就奏效了。


      更多细节:

      例如,如果我的/mnt/ntserver 下有文件test.txt 并有file:////mnt/ntserver 作为我的种子url,那么nutch 将正确解析/mnt/ntserver 的索引,并发现有一个名为@ 的文件987654327@,但随后它会尝试获取文件/mnt/test.txt。在种子 url 添加斜杠后,使其成为file:////mnt/ntserver/,nutch 现在尝试获取文件/mnt/ntserver/test.txt,解决了我的问题。

      顺便说一句,为了阻止 nutch 沿着文件夹树向上移动到根目录,我在 nutch-default.xml 中将 file.crawl.parent 设置为 false,但也可以通过 regex-urlfilter.xml 来完成。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-30
        • 2014-02-09
        • 1970-01-01
        相关资源
        最近更新 更多