我正在抓取 Stack Overflow,我已经捕获了标题、URL 和标签,但我无法捕获每个问题的投票。有人能帮我吗?我不太擅长 xpath
def parse_item(self, response):
questions = response.xpath('//div[@class="question-summary"]')
for question in questions:
item = StackItem()
item['url'] = question.xpath(
'div[@class="summary"]/h3/a[@class="question-hyperlink"]/@href').extract()[0]
item['title'] = question.xpath(
'div[@class="summary"]/h3/a[@class="question-hyperlink"]/text()').extract()[0]
item['tags'] = question.xpath(
'div[@class="summary"]/div[2]/a[@class="post-tag"]/text()').extract()
item['votes'] = question.xpath(
'/div[1]/div[1]/div[1]/div[1]/span/strong/textContent()').extract()[0]
yield item
我正在抓取页面: https://stackoverflow.com/questions?page=2&sort=newest
最佳答案
怎么样
item['votes'] = question.css('.vote-count-post > strong::text').extract()[0]
?
关于python - 使用 scrapy 在 Stack Overflow 中进行网页抓取,但我无法获得该问题的投票,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53196672/