美文网首页
scrapy Request之间传递参数

scrapy Request之间传递参数

作者: tenlee | 来源:发表于2018-06-08 17:18 被阅读60次

在构造Request时,meta参数可以作为参数传递的载体,meta内容并不会提交到请求中。
例如:

In [1]: fetch(scrapy.Request('http://httpbin.org/get',meta={'name':'张三'}))
In [2]: response.text
Out[2]: '{"args":{},"headers":{"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Encoding":"gzip,deflate","Accept-Language":"en","Connection":"close","Host":"httpbin.org","User-Agent":"Baiduspider"},"origin":"180.169.75.62","url":"http://httpbin.org/get"}\n'
In [5]: response.meta['name']
Out[5]: '张三'

相关文章

网友评论

      本文标题:scrapy Request之间传递参数

      本文链接:https://www.haomeiwen.com/subject/hobasftx.html