Python 官方文档:入门教程 => 点击学习
import urllib data = urllib.parse.urlencode(params).encode('utf-8') req = urllib.request.Request(url, data) req.add_head
import urllib
data = urllib.parse.urlencode(params).encode('utf-8')
req = urllib.request.Request(url, data)
req.add_header('Content-Type', "application/x-www-fORM-urlencoded")
response = urllib.request.urlopen(req)
the_page = response.read().decode('utf-8')
print(the_page)
如果不做encode,会直接报错:POST data should be bytes or an iterable of bytes. It cannot be of type str.
如果不做decode,看到的都是assic码
--结束END--
本文标题: python3 urllib用法
本文链接: https://lsjlt.com/news/193026.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0