【问题标题】:twisted CRITICAL: Unhandled error in Deferred:扭曲的 CRITICAL:延迟中未处理的错误:
【发布时间】:2019-10-01 19:54:54
【问题描述】:

我正在使用scrapy-splash 来抓取这个网站,蜘蛛给出“[twisted] CRITICAL: Unhandled error in Deferred:”

尝试了堆栈溢出和其他网站上的所有内容

我的蜘蛛代码

class DarazspidySpider(scrapy.Spider):
    name = 'darazspidy'

    def start_requests(self):
        url = 'https://www.daraz.pk/smartphones/'
        SplashRequest(url=url, callback=self.parse, 
     endpoint='render.html', args={'wait': 0.5})

    def parse(self, response):
        for phone in response.xpath('//div[@class="c5TXIP"]'):
            yield {
            'Name',
            phone.xpath('.//*[contains(concat( " ", @class, " " ), concat( " ", "c16H9d", " " ))]//a').extract(),
            'price',
            phone.xpath('.//*[contains(concat( " ", @class, " " ), concat( " ", "c13VH6", " " ))]').extract(),
        }

【问题讨论】:

  • 你可以试试yield你的SplashRequest吗?
  • 究竟是什么意思?

标签: python web-scraping scrapy scrapy-splash


【解决方案1】:

您正在生成一个集合,而不是字典。您可以尝试生成字典吗?

您的集合创建将失败,因为您无法将列表添加到集合中。

试试这样的:

def parse(self, response):
        for phone in response.xpath('//div'):
            yield {
            'Name': phone.xpath('.//*[contains(concat( " ", @class, " " ), concat( " ", "c16H9d", " " ))]//a').extract(),
            'price': phone.xpath('.//*[contains(concat( " ", @class, " " ), concat( " ", "c13VH6", " " ))]').extract(),
        }

您可能还需要提交启动请求:

yield SplashRequest(url=url, callback=self.parse, 
     endpoint='render.html', args={'wait': 0.5})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    相关资源
    最近更新 更多