【问题标题】:Scrapy returning NotImplementedErrorScrapy 返回 NotImplementedError
【发布时间】:2017-05-09 06:32:44
【问题描述】:

我在 Hostelworld.com 上运行以下 scrapy spider 来检索:

  • 首页上的大陆、国家和国家网址
  • 关注国家/地区网址后来自给定国家/地区的城市列表

    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

非常感谢您的帮助!

【问题讨论】:

    标签: scrapy scrapy-spider


    【解决方案1】:

    Scrapy Spider 需要定义 parse() 方法,而你没有。

    默认情况下,scrapy.Spider 链的工作方式是通过回调 self.parsestart_urls 中的每个 url 发出请求。

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-28
        • 2010-10-27
        • 2015-07-13
        • 2016-11-12
        • 2019-05-03
        相关资源
        最近更新 更多