[問題] 中文編碼
小弟是剛接觸PYTHON的新手 正在練習抓網頁的寫法
已經爬版和GOOGLE 還是找不到方法
先附上程式碼
import urllib
import urllib.request
thisurl = "http://www.cna.com.tw/"
handle = urllib.request.urlopen(thisurl)
html_gunk = handle.read().decode(encoding="utf-8",errors="ignore")
f = open('t.txt','w')
f.write(html_gunk)
然後出現錯誤訊息
Traceback (most recent call last):
File "openurl - wf.py", line 15, in <module>
f.write(html_gunk)
UnicodeEncodeError: 'cp950' codec can't encode character '\xf1' in position
15378: illegal multibyte sequence
麻煩高手指點迷津
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.212.247
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1450489489.A.B2A.html
→
12/19 09:53, , 1F
12/19 09:53, 1F
→
12/19 10:22, , 2F
12/19 10:22, 2F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章