小弟是刚接触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
麻烦高手指点迷津