【问题标题】:Scrapy : TypeError: argument of type 'NoneType' is not iterableScrapy:TypeError:“NoneType”类型的参数不可迭代
【发布时间】:2019-07-22 10:35:42
【问题描述】:

Whit scrapy,当我启动我的蜘蛛时,我收到了这个NoneType 错误:

如果 tab_arrivee_th 中的“Jockey”:TypeError:“NoneType”类型的参数 不可迭代

代码在list 的控制台测试中运行良好,但在response.css 下运行良好。 我认为问题来自response_arrivee_th,我不明白为什么,因为'scrapy shell'给了我一个列表作为回报,这和我在测试中使用的一样。

def parse(self, response):

    tab_arrivee_th = response.css('.arrivees th::text').extract()

  # list obtained whit the response.css from above in scrapy shell

  # tab_arrivee_th = ['Cl.', 'N°', 'Cheval', 'S/A', 'Œill.', 'Poids', 'Corde', 'Ecart', 'Jockey', 'Entraîneur', 'Tx', 'Récl.', 'Rapp. Ouv.']

    if 'Jockey' in tab_arrivee_th:
        col_jockey = tab_arrivee_th.index('Jockey') + 1
    elif 'Driver' in tab_arrivee_th:
        col_jockey = tab_arrivee_th.index('Driver') + 1
    else:
        col_jockey = 0


    jockey = partant.css('td:nth-child(' + str(col_jockey) + ') > a::text').extract()

如果 tab_arrivee_th 中的“Jockey”:TypeError:“NoneType”类型的参数 不可迭代

感谢帮助

【问题讨论】:

标签: scrapy nonetype


【解决方案1】:

已解决:'response.css('.arrivees th::text').extract()' 指向 js 中的列表构造。
所以我使用scrapy-splash 来延迟0.5 秒。它工作正常。

【讨论】:

    【解决方案2】:

    tab_arrivee_th = response.css('.arrivees th::text').extract() 这一行的响应为空,请再次检查响应。

    【讨论】:

    • 我刚刚检查过,响应是一个列表:['Cl.', 'N°', 'Cheval', 'S/A', 'Œill.', 'Poids', 'Corde '、'Ecart'、'Jockey'、'Entraîneur'、'Tx'、'Récl.'、'Rapp. Ouv.']
    猜你喜欢
    • 1970-01-01
    • 2017-01-07
    • 2011-10-04
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 2012-04-26
    • 1970-01-01
    相关资源
    最近更新 更多