2017-10-10 22 views
1

私はScrapyで自分のサイトをクロールし、404応答のリンクを見つけてそれらをJSONファイルに戻します。これは本当にうまくいく。スクラップで404エラーのすべてのインスタンスを取得する

しかし、重複フィルタはこれらのリンクをキャッチしていて、再試行していないので、その悪いリンクのすべてのインスタンスを取得する方法を理解できません。

私たちのサイトは何千ものページを持っているので、セクションは複数のチームによって管理されていますので、セクションごとの不良リンクのレポートを作成してサイト全体の検索を行うよりもむしろ作成する必要があります。

ご協力いただければ幸いです。

私の現在のクローラー:

import scrapy 
from scrapy.spiders import CrawlSpider, Rule 
from scrapy.linkextractors.lxmlhtml import LxmlLinkExtractor 
from scrapy.item import Item, Field 

# Add Items for exporting to JSON 
class DevelopersLinkItem(Item): 
    url = Field() 
    referer = Field() 
    link_text = Field() 
    status = Field() 
    time = Field() 

class DevelopersSpider(CrawlSpider): 
    """Subclasses Crawlspider to crawl the given site and parses each link to JSON""" 

    # Spider name to be used when calling from the terminal 
    name = "developers_prod" 

    # Allow only the given host name(s) 
    allowed_domains = ["example.com"] 

    # Start crawling from this URL 
    start_urls = ["https://example.com"] 

    # Which status should be reported 
    handle_httpstatus_list = [404] 

    # Rules on how to extract links from the DOM, which URLS to deny, and gives a callback if needed 
    rules = (Rule(LxmlLinkExtractor(deny=([ 
     '/android/'])), callback='parse_item', follow=True),) 

    # Called back to for each requested page and used for parsing the response 
    def parse_item(self, response): 
     if response.status == 404: 
      item = DevelopersLinkItem() 
      item['url'] = response.url 
      item['referer'] = response.request.headers.get('Referer') 
      item['link_text'] = response.meta.get('link_text') 
      item['status'] = response.status 
      item['time'] = self.now.strftime("%Y-%m-%d %H:%M") 

      return item 

私はいくつかのカスタムデュープフィルタを試してみたが、最終的にそれらのどれも働きました。

答えて

関連する問題