python__网络编程:urllib、requests模块

一、urllib模块:python自带的模块

 1、urllib模块的get请求:

from urllib import urlopen   #打开url
from urllib.parse import urlencode
#get请求:
url='https://api.nnzhp.cn/api/user/stu_info'
d={'stu_name':'小白'}
req=urlopen(url+'?'+urlencode(d))   #get请求的参数要转成二进制
print(req.read())   #返回的结果是bytes类型
print(req.read().decode())   #返回的结果转成字符串

  2、urllib模块的post请求:

猜你喜欢

转载自www.cnblogs.com/hancece/p/11121985.html