标签:准备工作 imp hone request请求 inf text one phone 服务器
这一部分需要用到request模块,准备工作就是安装request模块。
安装方法移步:https://www.cnblogs.com/jszfy/p/11210783.html
import requests
# 1、构造请求的URL
url = "http://..."
# 2、创建请求参数
params = {
"mobilephone": "18012345678",
"pwd": "123456",
"regname": "zfy"
}
headers ={
"User-Agent":"Mozillas/5.0 test"
}
# 3、向服务器发起请求
res = requests.get(url, params=params, headers=headers)
print(res.text)
print(res.json())
print(res.cookies)
res:返回的【response】对象,可以通过【res.属性名】来获取相应的属性内容。
根据URL可以看出,这里是使用【查询字符串参数】的格式进行传参的。


headers不一定要改,因为有的网站有反爬虫措施,所以需要自己添加合法的请求头。
但是大多数情况下不用修改。
标签:准备工作 imp hone request请求 inf text one phone 服务器
原文地址:https://www.cnblogs.com/jszfy/p/11337064.html