2017-05-08 35 views
0

我跑在Hostelworld.com以下scrapy蜘蛛,檢索:Scrapy歸國NotImplementedError

  • 大陸,在第一頁上發展中國家和網址
  • 的從一個給定的城市名單運行它的時候,我無法找到一個SOLUT已經遵循了國家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 
    

我收到以下錯誤後國家離子到:

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

非常感謝您的幫助!

回答

4

Scrapy Spider要求parse()要定義的方法,你沒有一個。

scrapy.Spider鏈如何在默認情況下工作是通過向start_urls中的每個網址發出請求並使用回調self.parse