一、requests是什么?
requests是一个很实用的Python HTTP客户端库,编写爬虫和测试服务器响应数据时经常会用到, Requests是Python语言的第三方的库,专门用于发送HTTP请求
二、下载
pip install requests
三、请求方式
1.get请求
GET无参请求
r = requests.get(‘http://www.baidu.com’)
GET有参请求
1.方法一
canshu = {“consName”: “水瓶座”,“key”:26183f3f48d787b5541aa3d0e767b359}
r = requests.get(“http://web.juhe.cn:8080/constellation/getAll”, params=canshu)
print®
2.方法二
r = requests.get(“http://web.juhe.cn:8080/constellation/getAll?consName=水瓶座&key=26183f3f48d787b5541aa3d0e767b359”)
print(r.text)
复制代码
2.post请求
canshu = {“consName”: “水瓶座”, “key”: “26183f3f48d787b5541aa3d0e767b359”}
r = requests.post(“http://web.juhe.cn:8080/constellation/getAll”, data=canshu)
print(r.text)
3.响应的内容
r.encoding # 获取当前的编码
r.encoding = ‘utf