看板 Python 關於我們 聯絡資訊
小弟是剛接觸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
alibuda174: open時也指定編碼utf-8試試 12/19 09:53
IsMe1086: 可以了!感謝你~~~ 12/19 10:22