2017-05-08 14 views
0

NotImplementedError返す:Scrapyは、私が取得するために、Hostelworld.comで次のscrapyクモを実行している

  • 最初のページにある大陸、国と国のURL
  • の都市のリストから与えられました国国のURL

    def parse_page1(self, response): 
        for sel in response.xpath('//li[@class="accordion-navigation"]//ul[@class="small-block-grid-2 medium-block-grid-4 large-block-grid-6"]/li'): 
         item = HostelWorldItem() 
         item['continent'] = sel.xpath('./../../@id').extract_first() 
         item['country'] = sel.xpath('./a/text()').extract_first() 
         item['country_url'] = sel.xpath('./a/@href').extract_first() 
    
         yield item 
    
         url = response.urljoin('%s'%(item['country_url'])) 
         request = scrapy.Request(url, callback=self.parse_dir_contents) 
         request.meta['item'] = item 
         yield request 
    
    def parse_dir_contents(self, response): 
        item = response.meta['item'] 
        item['city'] = response.xpath('//div[@class="otherlocations"]/li/a/text()').extract_first() 
        yield item 
    

を踏襲した後、それを実行するときに、私は次のエラーを取得する、と私はsolutを見つけることができませんそれまでのイオン:

scrapy/spiders/__init__.py", line 76, in parse 
raise NotImplementedError 
NotImplementedError 

ありがとうございました!

答えて

4

治療Spiderには、parse()のメソッドが定義されていて、それがありません。

デフォルトでscrapy.Spiderチェーンが動作するのは、すべてのURLにstart_urlsのコールバックself.parseでリクエストを行うことです。

関連する問題