【问题标题】:nutch to extract only pdf filesnutch 仅提取 pdf 文件
【发布时间】:2013-04-06 17:03:06
【问题描述】:

有什么方法可以执行 1-5 级的 urlfilter 和 5 级以后的不同 urlfilter。我需要提取只有在给定级别之后的 pdf 文件(只是为了实验)。

pdf 文件将以二进制格式存储在 crawl/segment 文件夹中。我想提取这些 pdf 文件并将所有文件存储在 1 个文件夹中。我已经能够编写一个 java 程序来识别一个 pdf 文件。我不知道如何制作一个 pdf 文件,其内容具有相同的字体、页码、图像等。

  1. 执行抓取
  2. 合并段数据
  3. 运行 makePDF.java

这仅识别 pdf 文件:

    String uri = "/usr/local/nutch/framework/apache-nutch-1.6/merged572/20130407131335";
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(URI.create(uri), conf);
    Path path = new Path(uri, Content.DIR_NAME + "/part-00000/data");

    SequenceFile.Reader reader = null;
    try {
      reader = new SequenceFile.Reader(fs, path, conf);
      Text key = new Text();
      Content content = new Content();
      while (reader.next(key, content)) {
          String contentType = content.getContentType();
          if (contentType.equalsIgnoreCase("application/pdf")) {
            //System.out.write( content.getContent(), 0, content.getContent().length );
            System.out.println(key);
          }
      }
      reader.close();
    } 
        finally {
        fs.close();
    }

【问题讨论】:

    标签: apache hadoop search-engine web-crawler nutch


    【解决方案1】:

    content.getContent() 将以字节为单位返回内容。
    只需使用 BufferedOutputStream 将字节写入文件并将其保存为 pdf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多