【问题标题】:Scrapy AttributeError: 'NoneType' object has no attribute 'css'Scrapy AttributeError:“NoneType”对象没有属性“css”
【发布时间】:2018-04-13 18:41:58
【问题描述】:

我正在尝试使用 Scrapy: 链接从该页面中抓取详细信息

这是我用来拉标题的命令,但它抛出了一个错误:

response.css('#intitule > div.nom_fugitif::text').extract_first()

这是错误:


AttributeError Traceback(最近调用 最后)在()中

----> 1 response.css('#intitule > div.nom_fugitif::text').extract_first()

AttributeError: 'NoneType' 对象没有属性 'css'

它说 div 没有 CSS,但我不确定这是什么意思,因为它确实有一个 CSS 类。

【问题讨论】:

  • 查看response的值。必须是None
  • @araraonline 我对此很陌生。你能解释一下吗?
  • 该错误并不是说 HTML 元素没有 CSS 类,而是说 response 对象是 None,因此没有您调用的方法 css response.css(...)。请显示完整的代码,以便我们检查。
  • 输入print(response),你会看到它可能是None
  • 它刚刚又开始工作了。不知道为什么!但是无论如何感谢您的帮助:)

标签: python css scrapy


【解决方案1】:

NoneType 表示您实际上在响应中得到了 None。 你可以检查

if response is not None:

【讨论】:

    猜你喜欢
    • 2020-12-24
    • 2019-01-01
    • 2021-12-26
    • 2019-07-23
    • 2018-05-13
    • 2020-09-07
    • 2017-05-03
    • 2023-03-16
    • 2018-07-14
    相关资源
    最近更新 更多