【发布时间】:2020-02-29 01:46:54
【问题描述】:
我正在尝试从BestBuy 中抓取评论,如果代码在shell 上逐行执行而不是通过script 执行,则它提取得很好。怎么了?
class BestbuybotSpider(scrapy.Spider):
name = 'bestbuybot'
allowed_domains = ['https://www.bestbuy.com/site/amazon-echo-dot-3rd-gen-smart-speaker-with-alexa-charcoal/6287974.p?skuId=6287974']
start_urls = ['http://https://www.bestbuy.com/site/amazon-echo-dot-3rd-gen-smart-speaker-with-alexa-charcoal/6287974.p?skuId=6287974/']
def parse(self, response):
#Extracting the content using css selectors
rating = response.css("div.c-ratings-reviews-v2.v-small p::text").extract()
title = response.css(".review-title.c-section-title.heading-5.v-fw-medium ::text").extract()
#Give the extracted content row wise
for item in zip(rating,title):
#create a dictionary to store the scraped info
scraped_info = {
'rating' : item[0],
'title' : item[1],
}
#yield or give the scraped info to scrapy
yield scraped_info
【问题讨论】:
标签: web-scraping scrapy scrapy-pipeline