request里面的meta 的使用
import scrapy
class Xs2Spider(scrapy.Spider):
name = "爬虫名"
allowed_domains = ["域名"]
start_urls = ["url地址"]
def parse(self, response):
# 章节名称
title = response.xpath('//div[@id="list"]/dl/dd[10]/a/text()').get()
# 第一章的url
url = response.xpath('//div[@id="list"]/dl/dd[10]/a/@href').get()
# 发送请求
full_url = response.urljoin(url)
yield scrapy.Request(full_url,callback=self.parse_info,meta={'title':title})
def parse_info(self,response):
content = response.xpath('//div[@id="content"]/text()').getall()
title = response.request.meta['title']
yield {
'title':title,
'content':content
}
meta的使用
使用字典拼接再一起,会遇到多个