scrapy爬虫框架爬取数据就第一个标题链接的数据,无法找到原因
import scrapy
from fl.items import FlItem
class XsSpider(scrapy.Spider):
name = "xs"
allowed_domains = ["b.faloo.com"]
start_urls = ["https://b.faloo.com/html_1270_1270410/"]
def parse(self, response):
datas = response.xpath('/html/body/div[2]/div[3]/div[4]/div[3]')
for a in datas:
name = a.xpath('./a/span/text()').get()
link = a.xpath('./a/@href').get()
url = 'https:' + link
yield scrapy.Request(url=url, callback=self.parse_li, meta={'name': name})
def parse_li(self, response):
item = FlItem()
item['name'] = response.meta['name']
item['datas'] = response.xpath('//*[@id="center"]/div/div[5]/p//text()').getall()
yield item