Python 和 Scrapy 的属性问题

Python and Scrapy issue with attrib

大家好,新年快乐:D

我是 scrapy 的新手,想使用 attrib 方法来充分理解它。我用了 this site 用于刮擦。当我 运行 response.css(".quote span").attrib["itemprop"] 它给出错误 SelectorList object has no attribute "attrib" 即使有这种方法。如何编写它才能使其工作以及为什么它不能以这种方式工作?

你可以试试这个 css 选择器

[x.attrib['itemprop'] for x in response.css('span.text')] 

或使用 xpath

response.xpath('//div[@class="quote"]/span/@itemprop').extract()