在 scrapy 中使用 for 循环从多个 url 中抓取信息
scrape information from multiple urls using a for loop in scrapy
我想从多个网址中抓取信息。我使用以下代码,但它不起作用。有人可以指出我哪里出错了吗?
import scrapy
class spider1(scrapy.Spider):
name = "spider1"
domain = "http://www.amazon.com/dp/"
ASIN = ['B01LA6171I', 'B00OUKHTLO','B00B7LUVZK']
def start_request(self):
for i in ASIN:
yield scrapy.Request(url=domain+i,callback = self.parse)
def parse(self, response):
title =response.css("span#productTitle::text").extract_first().strip()
ASIN_ext = response.xpath("//input[@name='ASIN']/@value").extract_first()
data = {"ASIN":ASIN_ext,"title":title,}
yield data
你只需要在第一个函数中添加一个's'
def start_requests(self):
细微差别,但 Scrapy 寻找特定功能,因此它必须完美匹配。
我想从多个网址中抓取信息。我使用以下代码,但它不起作用。有人可以指出我哪里出错了吗?
import scrapy
class spider1(scrapy.Spider):
name = "spider1"
domain = "http://www.amazon.com/dp/"
ASIN = ['B01LA6171I', 'B00OUKHTLO','B00B7LUVZK']
def start_request(self):
for i in ASIN:
yield scrapy.Request(url=domain+i,callback = self.parse)
def parse(self, response):
title =response.css("span#productTitle::text").extract_first().strip()
ASIN_ext = response.xpath("//input[@name='ASIN']/@value").extract_first()
data = {"ASIN":ASIN_ext,"title":title,}
yield data
你只需要在第一个函数中添加一个's'
def start_requests(self):
细微差别,但 Scrapy 寻找特定功能,因此它必须完美匹配。