python_requests模块

1、安装

pip install requests

2、get请求

如果需要加cookie可以直接加在headers中

import requests
#get请求带参数
url="http://xxx/api/user/stu_info"
data={"stu_name":"矿泉水1"}
result=requests.get(url,data)
print(result.json()) #返回字典类型
print(result.text) #返回一个字符串类型
print(result.content) #返回bytes类型

#get请求无参数
url2='http://q4.qlogo.cn/g?b=qq&nk=xxx&s=140'
result2=requests.get(url2)
fw=open("jjj.png",'wb') #get请求结果写入文件
fw.write(result2.content)
fw.close()

 3、post 请求

猜你喜欢

转载自www.cnblogs.com/xiaokuangnvhai/p/11120689.html