python 如何将 curl 请求转换为请求模块

How to convert curl request to requests module in python

如何将此 curl 请求转换为 python 请求模块兼容(Post 请求)

curl 'http://sss.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36' -H --data 'aq=%40syssource%3DProFind%20AND%20NOT%20%40title%3DCoveo%20AND%20NOT%20%40title%3Derror&searchHub=ProFind&xxx=yyy&xxx=yyy&xxx=yyy=10&xxx=yyy' --compressed

我在这里搜索请求模块

http://docs.python-requests.org/en/master/user/quickstart/

但他们只有数据值作为键,值

r = requests.post('http://httpbin.org/post', data = {'key':'value'})

那么如何将上面的 curl post 请求转换为 python 请求模块来制作 post 请求

您链接的文档说:

There are many times that you want to send data that is not form-encoded. If you pass in a string instead of a dict, that data will be posted directly.

所以只需使用

r = requests.post('http://sss.com', data = 'aq=%40syssource%3DProFind%20AND%20NOT%20%40title%3DCoveo%20AND%20NOT%20%40title%3Derror&searchHub=ProFind&xxx=yyy&xxx=yyy&xxx=yyy=10&xxx=yyy')