如何使用scrapy在请求上指定参数 [英] How to specify parameters on a Request using scrapy
本文介绍了如何使用scrapy在请求上指定参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将参数传递给这样的 url 请求:
How do I pass parameters to a a request on a url like this:
site.com/search/?action=search&description=My Search here&e_author=
我如何将参数放在蜘蛛请求的结构上,就像这个例子:
How do I put the arguments on the structure of a Spider Request, something like this exemple:
req = Request(url="site.com/",parameters={x=1,y=2,z=3})
推荐答案
在 URL 内部传递 GET 参数:
Pass your GET parameters inside the URL itself:
return Request(url="https://yoursite.com/search/?action=search&description=MySearchhere&e_author=")
您可能应该在字典中定义参数,然后"urlencode" 它:
You should probably define your parameters in a dictionary and then "urlencode" it:
from urllib import urlencode
params = {
"action": "search",
"description": "My search here",
"e_author": ""
}
url = "https://yoursite.com/search/?" + urlencode(params)
return Request(url=url)
这篇关于如何使用scrapy在请求上指定参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文