requests模块发送带headers的Get请求和带参数的请求

1.在PyCharm开发工具中新建try_params.py文件;

   2.try_params.py文件中编写代码:

 
import requests
#设置请求Headers头部
header = {"User-Agent" : "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"}
#请求输入参数
p = {"wd":"老男孩"}
#请求url
url_temp = "https://www.baidu.com/s?"
#requests发送请求
result = requests.get("url_temp",headers=header,params=p)
#请求响应状态
print(result.status_code)
3.运行try_params.py
4.程序报告如下错误:异常原因python中还没有安装requests库

 4.安装pip install requests 执行安装(在cmd中输入pip install requests),等待安装完成

4.执行py文件;

猜你喜欢

转载自www.cnblogs.com/simpleBlue3/p/10630523.html