【发布时间】:2018-12-27 10:15:38
【问题描述】:
我正在使用scrapy,并希望将所有标签(带有文本)存储在一个列表中,并通过该列表逐个div获得我想要的内容。
在我的代码下面,我将所有我想要的标签存储在 div 中,这没关系,但是之后的循环不起作用。错误:('str'对象没有属性'css')
def parse_0(self, response):
divs = response.css('div.resultList.mB15.hiddenOverflow.listing').extract()
for div in divs:
yield {
'prix': str(div.css('div.fieldPrice ::text').extract_first()).replace("\\xa0", "").replace("\u20ac", ""),
'lien': div.xpath('.//a/@href').extract_first(),
'date_scrap': time.strftime("%d/%m/%Y"),
}
这里是代表嵌入 div 的图像: enter image description here 谢谢
【问题讨论】:
-
如果我使用这个(这是没有提取的解决方案):for div in response.css('div.resultList.mB15.hiddenOverflow.listing'): blabla .... 循环在之后停止第一次迭代。
-
你确定有超过 1 个 div 吗?如果您附上您正在抓取的页面的网址,我们会更容易提供帮助。
-
@stasdeep 我添加了显示嵌入 div 的图像,对我来说,我需要获取存储在每个 div adLineContainer 中的每个价格和链接
-
我看到您正在检查浏览器中呈现的 HTML,但原始响应可能看起来不同。