码迷,mamicode.com
首页 > 编程语言 > 详细

python3 urllib用法

时间:2017-02-23 23:03:48      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:python3 urllib

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码

python3 urllib用法

标签:python3 urllib

原文地址:http://wangfeng7399.blog.51cto.com/3518031/1900613

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!