其他分享
首页 > 其他分享> > 网络请求urllib day07-12

网络请求urllib day07-12

作者:互联网

# 1.post
# 2.get
# 3.url里面传参
# 4.body json
# 5.cookie
# 6.header
# 7.k -v
# 8.上传文件
from urllib.request import urlopen
from urllib.parse import urlencode,urljoin,quote_plus,quote,unquote_plus

host = "http://api.nnzhp.cn/?stu_name=小黑"
# unquote 解码
# unquote_plus 解码
url = "https://www.baidu.com/s?wd=%E5%93%88%E5%93%88%E5%93%88"
print(unquote_plus(url))

# quote_plus url编码 把中文或者特殊字符转变为编码
print(quote_plus(host))
# quote 编码
print(quote(host))

# host = "http://api.nnzhp.cn/"
# urljoin
# url = urljoin(host,'/api/login') # URL 地址拼接
# print(url)

# url = "http://api.nnzhp.cn/api/user/stu_info"
data = {"stu_name":"xiaohei","age":18}
# print(urlencode(data)) # 把字典转为 谁等于谁

# req = urlopen(url,urlencode(data).encode()) # post请求
# print(req.read().decode)

# req = urlopen(url+'?'+urlencode(data)) # get请求
# print(req.read().decode)

标签:urlencode,12,url,quote,day07,urllib,api,plus,print
来源: https://www.cnblogs.com/huyuemei/p/14881280.html