获取带查询字符串参数的响应对象,如下所示:
import requests
data = {
'name': '编程帮',
'url': "www.biancheng.net"
}
response = requests.get('http://httpbin.org/get', params=data)
#直接拼接参数也可以
#response = requests.get(http://httpbin.org/get?name=gemey&age=22)
#调用响应对象text属性,获取文本信息
print(response.text)
输出结果:
{
"args": {
"name": "\u7f16\u7a0b\u5e2e",
"url": "www.biancheng.net"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.23.0",
"X-Amzn-Trace-Id": "Root=1-60420026-236f9205646b68706d0fafa7"
},
"origin": "121.17.25.194",
"url": "http://httpbin.org/get?name=\u7f16\u7a0b\u5e2e&url=www.biancheng.net"
}