#导入所需要的库
import requests
headers={
"User-Agent":"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
}
kd={
'wd':'长城'
}
#1、模拟浏览器发起基本的get请求,并得到响应response 请求的url为:http://www.baidu.com
#2、如果要将参数放在url中传递,可以利用params参数。
#2、params接收一个字典或者字符串的查询参数,字典类型自动转换为url编码,不需要urlenconde()
#3、如果想添加headers,可以传入headers参数来参加请求头中headers信息,
response=requests.get("http://www.baidu.com",params=kd,headers=headers)
#查看响应的内容,response.text返回的是Unicode格式的数据
print(response.text)
#查看响应的内容,response.content返回的字节流数据
print(response.content)
#查看响应的内容,查看完整的url地址
print(response.url)
#查看响应头部字符的编码
print(response.encoding)
#查看响应编码
print(response.status_code)
python3-get
最新推荐文章于 2024-05-11 11:25:51 发布