我试图从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发布于 2020-05-13 20:12:32
您的代码存在一些问题,即
allowed_domains应该是一个域而不是一个URL。处有'http://https:
正如您所看到的,抓取的爬行器重定向到您的图像中的finder.cox.net,因此爬行器永远不会到达页面,而是显示一个国家选择页面,这是一个重定向页面。
您应该尝试并首先使用确切的页面位置来修复您的起始URL,爬行器似乎可以正常工作。
https://stackoverflow.com/questions/60461286
复制相似问题