中英文微信网站开发,免费网站建设哪个好?,惠安县住房和城乡建设局网站,网站被墙的原因Requests的深入了解
基本POST请求#xff08;data参数#xff09;
1. 最基本post方法
response requests.post(http://www.baidu.com/, data data)2. 传入data数据
对于 POST 请求来说#xff0c;我们一般需要为它增加一些参数。那么最基本的传参方法可以…Requests的深入了解
基本POST请求data参数
1. 最基本post方法
response requests.post(http://www.baidu.com/, data data)2. 传入data数据
对于 POST 请求来说我们一般需要为它增加一些参数。那么最基本的传参方法可以利用 data 这个参数。
import requestsformdata {type:AUTO,i:i love python,doctype:json,xmlVersion:1.8,keyfrom:fanyi.web,ue:UTF-8,action:FY_BY_ENTER,typoResult:true
}url http://fanyi.youdao.com/translate?smartresultdictsmartresultrulesmartresultugcsessionFromnullheaders{ User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36}response requests.post(url, data formdata, headers headers)print (response.text)# 如果是json文件可以直接显示
print (response.json())代理proxies参数
如果需要使用代理你可以通过为任意请求方法提供 proxies 参数来配置单个请求
import requests# 根据协议类型选择不同的代理
proxies {http: http://12.34.56.79:9527,https: http://12.34.56.79:9527,
}response requests.get(http://www.baidu.com, proxies proxies)
print response.text也可以通过本地环境变量 HTTP_PROXY 和 HTTPS_PROXY 来配置代理
export HTTP_PROXYhttp://12.34.56.79:9527
export HTTPS_PROXYhttps://12.34.56.79:9527私密代理验证特定格式 和 Web客户端验证auth 参数
私密代理
import requests# 如果代理需要使用HTTP Basic Auth可以使用下面这种格式
proxy { http: mr_mao_hacker:sffqry9r61.158.163.130:16816 }response requests.get(http://www.baidu.com, proxies proxy)print (response.text)web客户端验证
如果是Web客户端验证需要添加 auth (账户名, 密码)
import requestsauth(test, 123456)response requests.get(http://192.168.199.107, auth auth)print (response.text)