当前位置:网站首页>scrapy.Request() 的 meta参数 数据的传递
scrapy.Request() 的 meta参数 数据的传递
2022-06-22 10:18:00 【侯小啾】
scrapy.Request() 的 meta参数 数据的传递
在既需要解析列表页,有需要解析详情页的情况下时,
以 以下模板代码为例,因为原本只在parse函数中定义了ABC类的实例化对象item,
所以这需要将item从parse()函数中传递到parse_detail()函数中,才能继续将数据收入item中,然后一块儿传递出去。
这需要用到scrapy.Request()的 meta 参数,
在scrapy.Request()中传入,传入时需要写为字典形式,字典的键名随便起即可。
如 meta={‘abcdefg’: item}
在parse_detail()中将其取出,取出时的键名只需与上边的保持一致。取出代码示例:
item = response.meta.get(‘abcdefg’)
class RecruitnameSpider(scrapy.Spider):
*************************
# 解析列表页
def parse(self, response):
result = response.*****************
for r in result:
item = ABC()
item['a'] = ***
item['b'] = ***
item['c'] = ***
******
yield scrapy.Request(
url=new_detail_url,
callback=self.parse_detail,
# 数据传递
meta={
'itemes': item}
)
# 解析详情页
def parse_detail(self, response):
item = response.meta.get('itemes')
item['d'] = ***
item['e'] = ***
item['f'] = ***
其中ABC类是 items.py文件中定义好的类。
边栏推荐
- Cobalt Strike 從入門到入獄(三)
- 【jenkins】shell脚本调jenkins api接口
- 字节三面:到底知不知道什么是Eureka?
- 【无标题】#修复日志#
- 蓝牙、wifi、zigbee和lora、NB-lot,通话信号,网络信号4G
- HMS core news industry solution: let technology add humanistic temperature
- 被曝泄露超 1.7 亿条隐私数据,学习通回应:尚未发现明确证据
- 力扣 1108. IP 地址无效化
- Start from the principle of MVC and knock on an MVC framework to bring you the pleasure of being a great God
- Qt编写物联网管理平台36-通信协议
猜你喜欢

【深度学习】不得了!新型Attention让模型提速2-4倍!

QT compile the Internet of things management platform 36- communication protocol

Cobalt Strike 從入門到入獄(三)

Who says PostgreSQL has no reliable high availability (2)

Quickly master asp Net authentication framework identity - login and logout

It is said that the price of the iPhone 14 will rise; TikTok US user data is transferred to Oracle, and bytes cannot be accessed; Seatunnel 2.1.2 releases geek headlines

Advanced Web Zone record of attack and defense world (I)

Xidian AI ranked higher than Qingbei in terms of AI major, and Nantah ranked first in China in terms of Software Science in 2022

Summary of neural network training trick

Force buckle 1108 IP address invalidation
随机推荐
Catch up with this big guy
xlrd.biffh.XLRDError: Excel xlsx file; not supported 解决办法
[backtrader source code analysis 51] simple interpretation of the source code of seven files in observers (boring, for reference only)
使用 Matplotlib 这么久,竟不知道数据可以动起来
SQLMap-hh
logstash中Ruby代码把@timestamp时间戳格式转换
软件工程 大题
How to transfer the values in the database to JSP pages through servlets and display them in El expressions?
抖音实战~手机号一键注册登录流程(验证码)
科研奖励,创业奖励评定
MySQL中from_unixtime和unix_timestamp处理数据库时间戳转换问题-案例
ipv4到ipv6过渡的三种方案
Zuckerberg's latest VR prototype is coming. It is necessary to confuse virtual reality with reality
6-32 construction of linked list by header insertion method
MYSQL Skip Scan Range 小功能,解决大问题 ?
信号完整性(SI)电源完整性(PI)学习笔记(二十四)差分对与差分阻抗(四)
iNFTnews | 观点:市场降温或是让NFT应用走向台前的机会
Pycharm调试卡住,出现connected
【科普】一文弄懂监督式学习、非监督式学习以及强化式学习
thinkphp5.0.24反序列化漏洞分析