我是scrapy的新手,在这里我创建了一个使用亚马逊网址的蜘蛛无法获得输出到csv。使用scrapy创建一个蜘蛛,并无法将数据存储到csv
这里是我的代码:
import scrapy
class AmazonMotoMobilesSpider(scrapy.Spider):
name = "amazon"
start_urls = ['https://www.amazon.in/Samsung-Mobiles/b/ref=amb_link_47?ie=UTF8&node=4363159031&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_s=merchandised-search-leftnav&pf_rd_r=NGA52N9RAWY1W103MPZX&pf_rd_r=NGA52N9RAWY1W103MPZX&pf_rd_t=101&pf_rd_p=1ce3e975-c6e8-479a-8485-2e490b9f58a9&pf_rd_p=1ce3e975-c6e8-479a-8485-2e490b9f58a9&pf_rd_i=1389401031',]
def parse(self,response):
product_name = response.xpath('//h2[contains(@class,"a-size-base s-inline s-access-title a-text-normal")]/text()').extract()
product_price = response.xpath('//span[contains(@class,"a-size-base a-color-price s-price a-text-bold")]/text()').extract()
yield {'product_name'product_name,'product_price': product_price}
我的壳呈现这样的结果:
len(response.xpath('//h2[contains(@class,"a-size-base s-inline s-access-tit le a-text-normal")]/text()')) 24
我是否需要更改任何设置?
你如何运行刮刀?你在日志中遇到任何错误?还检查错字@Arun提到的是什么导致问题 –
我运行我的蜘蛛是这样的:scrapy crawl spidername,没有错误我的外壳给我结果的计数但不输出到CSV –