【发布时间】:2021-07-03 21:06:50
【问题描述】:
这是代码
import scrapy
class YelpscrapeSpider(scrapy.Spider):
name = 'yelpscrape'
start_urls = ['https://www.yelp.com/biz/beretta-san-francisco?osq=Restaurants']
def parse(self, response):
for review in response.css('ul.undefined.list__373c0__3GI_T'):
item = {
'review': review.css('p.comment__373c0__1M-px.css-n6i4z7 span').get()
}
yield item
这是它返回的内容
[
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": "Correct review"},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null},
{"review": null}
]
我只是不太明白要更改什么,所以它会正确返回。我到处玩,得到了 18 份相同的评论,这也不是我想要的。你们能帮我解决这个问题吗?
【问题讨论】:
-
检索 review: 值对时,该值基于“p.comment__373c0__1M-px.css-n6i4z7 span”css 选择器。问题可能是由于不同的评论具有不同的 CSS 值,而不是您输入的值。唯一具有该值的评论是第 9 条,即有效的评论。
标签: python scrapy screen-scraping scrape