但是在做任何建议之前,我想在这里问一问,因为我真的不喜欢任何方法。
所以,基本上,我在尝试刮蒸汽游戏。正如您可能知道的,蒸汽有一个链接,您可以在其中访问游戏的所有评论,例如:
https://steamcommunity.com/app/730/reviews/?browsefilter=toprated&snr=1_5_100010_
您可以忽略snr和browsefilter查询参数。
无论如何,我已经创建了一个单独的蜘蛛,它将在这里爬行游戏列表,并且运行得很好:
https://store.steampowered.com/search/?sort_by=Released_DESC
但是现在,对于每一个游戏,我想检索所有的评论。
最初,我创建了一个新的Spider,用于处理页面中的无限滚动,其中包含了对游戏的全部评论,但是很明显,蜘蛛需要那些评论所在的URL。
因此,我现在所做的基本上是刮除所有游戏页面,并将每个游戏的评论存储在txt文件中,然后作为参数传递给第二个蜘蛛。但我不喜欢这样,因为它迫使我做两个步骤的过程,而且,我还需要将第二个蜘蛛的结果映射到第一个蜘蛛的结果(这个评论属于这个游戏,等等)。
所以我的问题是:
。
,
。
发布于 2019-11-07 10:36:53
为什么不使用不同的解析过程呢?
https://docs.scrapy.org/en/latest/intro/tutorial.html#more-examples-and-patterns
def parse(self, response):
# follow links to author pages
for href in response.css('.author + a::attr(href)'):
yield response.follow(href, self.parse_author)
# follow pagination links
for href in response.css('li.next a::attr(href)'):
yield response.follow(href, self.parse)
def parse_author(self, response):
def extract_with_css(query):
return response.css(query).get(default='').strip()
yield {
'name': extract_with_css('h3.author-title::text'),
'birthdate': extract_with_css('.author-born-date::text'),
'bio': extract_with_css('.author-description::text'),
}
# follow pagination links
for href in response.css('li.next a::attr(href)'):
yield response.follow(href, self.parse_author)并使用meta标记添加所需的值:
https://docs.scrapy.org/en/latest/topics/request-response.html#scrapy.http.Request.meta
Is it possible to pass a variable from start_requests() to parse() for each individual request?中的示例
https://stackoverflow.com/questions/58746174
复制相似问题