1.Request 请求头定制
添加http头部,使用headers调用即可
代码:
import requests
base_url='http://httpbin.org'
param_data={'user':'wx','password':'123456'}
header={'user-agent':'mozilla/8.0'}
r=requests.post(base_url+'/post',data=form_data,headers=header)
print(r.text)
运行结果
2.访问知乎页面
访问知乎页面,f12找到user_agent字段内容
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
代码:
import requests
param_data={'user':'wx','password':'123456'}
header={'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}
r=requests.get('https://www.zhihu.com/',headers=header)
print(r.text)
2.响应内容
网友评论