1

我需要从几个不同的网站(主要是 HTML 页面和 PDF 文档)聚合内容。我目前正在试验 Heritrix (3.2.0),看看它是否能满足我的需求。

虽然文档非常详细,但引擎似乎并没有像我预期的那样工作。我已经设置了一些简单的工作,并以多种不同的方式配置了 DecideRules,但无论我做什么,我发现 Heritrix 要么拉下太多内容,要么什么都没有。

这是我正在尝试做的一个例子。我将 Heritrix 指向这样的 URL...example.com/news/speeches。这是一个网页,其中包含一个 HTML 表格,其中包含指向各个演讲的链接(例如..example.com/news/speech/speech1.html、xample.com/news/speech/speech2.html 等)。我真的只需要比父页面低一级的 HTML 和 PDF 文档。我想防止 Heritrix 导航超过 1 级,如果不在 example.com 域上的此特定路径下方,防止它拉取内容,防止它导航到另一个域,并将其限制为 html 和 pdf 内容。

以下配置是我认为应该工作但没有

 <bean id="longerOverrides" class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
      <property name="properties">
       <props>
        <prop key="seeds.textSource.value">

    # URLS HERE
    example.com/news/speeches

        </prop>
       </props>
      </property>
     </bean>

<bean id="scope" class="org.archive.modules.deciderules.DecideRuleSequence">
  <!-- <property name="logToFile" value="false" /> -->
  <property name="rules">
   <list>
    <!-- Begin by REJECTing all... -->
    <bean class="org.archive.modules.deciderules.RejectDecideRule">
    </bean>
    <!-- ...then ACCEPT those within configured/seed-implied SURT prefixes... -->
    <bean class="org.archive.modules.deciderules.surt.SurtPrefixedDecideRule">
     <!-- <property name="seedsAsSurtPrefixes" value="true" /> -->
     <!-- <property name="alsoCheckVia" value="false" /> -->
     <!-- <property name="surtsSourceFile" value="" /> -->
     <!-- <property name="surtsDumpFile" value="${launchId}/surts.dump" /> -->
      <property name="surtsSource">
           <bean class="org.archive.spring.ConfigString">
            <property name="value">
             <value>
            example.com/news/speeches
             </value>
            </property> 
           </bean>
          </property>
    </bean>
     <!-- ...and REJECT those from a configurable (initially empty) set of URI regexes... -->
<bean class="org.archive.modules.deciderules.MatchesListRegexDecideRule">
      <property name="decision" value="REJECT"/>
      <property name="listLogicalOr" value="true" />
      <property name="regexList">
       <list>
         <value>.*(?i)(\.(avi|wmv|mpe?g|mp3))$</value>
         <value>.*(?i)(\.(rar|zip|tar|gz))$</value>
         <value>.*(?i)(\.(xls|odt))$</value>
         <value>.*(?i)(\.(xml))$</value>
         <value>.*(?i)(\.(txt|conf|pdf))$</value>
         <value>.*(?i)(\.(swf))$</value>
         <value>.*(?i)(\.(js|css))$</value>
         <value>.*(?i)(\.(bmp|gif|jpe?g|png|svg|tiff?))$</value>
       </list>
      </property>
</bean>
    <!-- ...but REJECT those more than a configured link-hop-count from start... -->
    <bean class="org.archive.modules.deciderules.TooManyHopsDecideRule">
     <!-- <property name="maxHops" value="20" /> -->
    </bean>
    <!-- ...but ACCEPT those more than a configured link-hop-count from start... -->
    <!--bean class="org.archive.modules.deciderules.TransclusionDecideRule"-->
     <!-- <property name="maxTransHops" value="2" /> -->
     <!-- <property name="maxSpeculativeHops" value="1" /> -->
    <!--/bean-->
    <!-- ...but REJECT those from a configurable (initially empty) set of REJECT SURTs... -->
    <bean class="org.archive.modules.deciderules.surt.SurtPrefixedDecideRule">
          <property name="decision" value="REJECT"/>
          <property name="seedsAsSurtPrefixes" value="false"/>
          <property name="surtsDumpFile" value="${launchId}/negative-surts.dump" /> 
     <!-- <property name="surtsSource">
           <bean class="org.archive.spring.ConfigFile">
            <property name="path" value="negative-surts.txt" />
           </bean>
          </property> -->
    </bean>
    <!-- ...and REJECT those from a configurable (initially empty) set of URI regexes... -->
    <bean class="org.archive.modules.deciderules.MatchesListRegexDecideRule">
          <property name="decision" value="REJECT"/>
     <!-- <property name="listLogicalOr" value="true" /> -->
     <!-- <property name="regexList">
           <list>
           </list>
          </property> -->
    </bean>
    <!-- ...and REJECT those with suspicious repeating path-segments... -->
    <bean class="org.archive.modules.deciderules.PathologicalPathDecideRule">
     <!-- <property name="maxRepetitions" value="2" /> -->
    </bean>
    <!-- ...and REJECT those with more than threshold number of path-segments... -->
    <bean class="org.archive.modules.deciderules.TooManyPathSegmentsDecideRule">
     <!-- <property name="maxPathDepth" value="20" /> -->
    </bean>
    <!-- ...but always ACCEPT those marked as prerequisitee for another URI... -->
    <bean class="org.archive.modules.deciderules.PrerequisiteAcceptDecideRule">
    </bean>
    <!-- ...but always REJECT those with unsupported URI schemes -->
    <bean class="org.archive.modules.deciderules.SchemeNotInSetDecideRule">
    </bean>
   </list>
  </property>
 </bean>

我希望我的爬虫只下载十几个 html 文档,因为这就是 /speech 路径中包含的所有内容。大约半小时后,我停止了爬网,因为它正在下载 800 多个文档,因为我发现它正在向后遍历到父级路径。我还尝试了 RegEx 规则,但没有成功。任何帮助,将不胜感激。

4

1 回答 1

0

调试此类问题的一件好事是启用范围决策的日志记录。(取消注释logToFile并使其成为true。这将为您的每个 URI 提供做出包含或拒绝它的决定的规则。因此,您将能够看到您的哪些规则没有正确配置并接受应该已经被拒绝。

于 2017-01-10T15:16:58.137 回答