2017-05-08 41 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