【发布时间】:2023-03-10 17:45:01
【问题描述】:
我必须在下面的 html 代码中提取文本内容以进行 python 网页抓取,问题在于类参数所有三个变量都具有相同的类参数,所以我尝试使用不起作用的 arial-label。
2,
3
Property_beds = response.css('.b6a29bc0::text').extract()
结果 得到两个变量“床”,“浴室”,我只想要一个变量浴室
'Property_beds':[2,3]
但我想在 response.css() 中包含 aria-label="Baths",我尝试使用以下代码但输出列表为空
Property_beds = response.css('span.b6a29bc0aria-label[attribute="Beds"]::text').extract()
【问题讨论】:
-
请添加您要解析的 html 的一些代码和示例/sn-p。
-
? Property_beds = response.css('span.b6a29bc0[aria-label=Beds]::text').extract()
-
这是我正在尝试收集废品的网站 [bayut.com/to-rent/property/dubai/] 如果数据具有相同的类
-
嗨,Harr,感谢您的回答帮助我解决了这个问题,但最后,在某些变量上没有 aria-label = bed 但有 aria-label= **Studio,所以我需要提供多个 aria-label 像这样 Property_baths = response.css('span.b6a29bc0[aria-label=[Beds,Studio]:: text').extract() 但这不起作用。请让我知道如何给出多个 arial-labels。
-
我使用下面的美丽汤正确处理了它 property_beds = soup.findAll('span',{'class':'b6a29bc0','aria-label':['Beds', 'Studio']}) 但是当我尝试使用scrapy时它不起作用。
标签: python css web-scraping web-crawler