python抓取网页编码问题
2017-01-13 15:22
211 查看
抓取的网页如果包含中文,那么正确打印和保存网页就需要解码和编码
import urllib
url = 'http://example.com/'
html = urllib.urlopen(url).read()
unicode = html.decode("utf-8")
gbkcode = unicode.encode("gbk")
print(gbkcode)
f = open("hello.txt", "w")
f.write(gbkcode)
f.close
import urllib
url = 'http://example.com/'
html = urllib.urlopen(url).read()
unicode = html.decode("utf-8")
gbkcode = unicode.encode("gbk")
print(gbkcode)
f = open("hello.txt", "w")
f.write(gbkcode)
f.close
相关文章推荐
- 黄聪:python访问抓取网页常用命令(保存图片到本地、模拟POST、GET、中文编码问题)
- python抓取gb2312/gbk编码网页乱码问题
- 黄聪:python访问抓取网页常用命令(保存图片到本地、模拟POST、GET、中文编码问题)
- 用python去抓取网页上emoji的Unicode编码和SB Unicode编码
- python抓取网页时字符集转换问题处理方案分享
- python 3读网页文件及保存成本地文件,遇到的编码问题
- python使用requests爬取网页,遇到中文出现乱码的编码问题及解决
- python unicode 转中文 遇到的问题 爬去网页中遇到编码的问题
- Python抓取网页的性能问题
- python获取网页内容的相关编码问题
- Python 抓取网页乱码问题 以及EXCEL乱码
- python urllib2爬取网页,编码问题
- Python抓取网页的性能问题
- python抓取网页时字符集转换问题处理方案分享
- 用python进行分布式网页数据抓取(三)—— 编码实现
- python 处理抓取网页乱码问题一招鲜
- Python应用-[用Python去抓取网页上emoji的Unicode编码和SB Unicode编码]
- python 网页抓取中的中文乱码问题解决
- python 处理抓取网页乱码问题
- 【python】网页内容抓取遭遇乱码问题