You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heritrix 3.4.0爬取规则配置:如何加载页面嵌入内容?

Heritrix 3.4.0 嵌入资源爬取规则调整方案

你的问题出在规则顺序错误:当前配置先拒绝了所有非目标路径的内容,包括嵌入资源,导致后续的嵌入资源接受规则没有生效机会。Heritrix的规则是按顺序执行,一旦某条规则做出明确的ACCEPT/REJECT决定,后续规则就不再处理该链接。

调整后的规则逻辑

我们需要优先保留嵌入类型(E/X)的链接,再过滤掉非目标路径的普通链接,最后默认接受目标路径内的所有内容:

  1. 优先接受所有嵌入类型(E)和推测嵌入类型(X)的资源,无论其路径是否在目标范围内
  2. 拒绝所有不在site.domain/path路径下的普通链接
  3. 默认接受目标路径内的所有页面及资源
  4. 保留原有标准规则(跳数、路径检测等)

修改后的配置代码

<bean id="scope" class="org.archive.modules.deciderules.DecideRuleSequence">
  <property name="rules">
   <list>
     <!-- 1. 接受所有嵌入类型(E)和推测嵌入类型(X)的资源 -->
     <bean class="org.archive.modules.deciderules.MatchesAttributeDecideRule">
       <property name="decision" value="ACCEPT"/>
       <property name="attributeName" value="discoveryPath"/>
       <property name="regex" value="^[EX]$"/>
     </bean>
     
     <!-- 2. 拒绝site.domain/path路径外的所有内容 -->
     <bean class="org.archive.modules.deciderules.NotMatchesListRegexDecideRule">
       <property name="decision" value="REJECT"/>
       <property name="regexList">
         <list>
           <value>.*site\.domain/path/.*</value>
         </list>
       </property>
    </bean>
     
     <!-- 3. 默认接受剩余的目标路径内的内容 -->
     <bean class="org.archive.modules.deciderules.AcceptDecideRule" />
     
     <!-- 以下为原有标准规则,无需修改 -->
    <bean class="org.archive.modules.deciderules.TooManyHopsDecideRule">
     <!-- <property name="maxHops" value="20" /> -->
    </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>

关键说明

  • MatchesAttributeDecideRule:通过匹配链接的discoveryPath属性值(E/X),直接接受所有嵌入类资源,确保这类资源不会被后续的路径过滤规则拒绝
  • 规则顺序必须严格按照「嵌入资源优先接受 → 非目标路径拒绝 → 默认接受」的逻辑,才能同时满足爬取目标路径页面和加载嵌入资源的需求

内容的提问来源于stack exchange,提问作者Erik Melkersson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 09:21:35