作者bohan222 (哈哈哈)
看板Python
标题[问题] Python urllib.urlopen 抓取有繁体网页
时间Mon Jul 29 22:06:49 2013
请教大家
Python 2.7.3 有使用下面utf-8的宣告
#!/usr/bin/python
# -*- coding: utf-8 -*-
问题:
使用 web = urllib.urlopen(内容具有繁体中文的网站)
content = web.read()
想分析网页内容为繁体的部分,结果繁体部分会变成乱码,
似乎是ascii之类的编码问题
想请教有人有遇过这类型问题吗~谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.43.211.213
1F:推 IAMPF:还是说他是big5编码? 07/29 22:12
2F:→ bohan222:如果是big5要怎麽改 07/29 22:28
3F:→ uranusjr:content = web.decode(编码名称).read() 07/29 22:45
4F:→ bohan222:楼上方法~会出现AttributeError: addinfourl instance ha 07/29 23:15
5F:→ bohan222:s no attribute 'decode' 这是不是我有忽略或漏甚麽~ 07/29 23:17
6F:推 timTan:应该是 content.decode ~ 07/29 23:17
7F:→ uranusjr:写反了, 是要先 read... 07/29 23:23