看板 Python 關於我們 聯絡資訊
請教大家 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
IAMPF:還是說他是big5編碼? 07/29 22:12
bohan222:如果是big5要怎麼改 07/29 22:28
uranusjr:content = web.decode(編碼名稱).read() 07/29 22:45
bohan222:樓上方法~會出現AttributeError: addinfourl instance ha 07/29 23:15
bohan222:s no attribute 'decode' 這是不是我有忽略或漏甚麼~ 07/29 23:17
timTan:應該是 content.decode ~ 07/29 23:17
uranusjr:寫反了, 是要先 read... 07/29 23:23