Re: [問題] Python urllib.urlopen 抓取有繁體網頁
謝謝大家~
我有改成content.decode()方式:
web = urllib.urlopen("http://www.emega.com.tw/js/StockTable.htm")
程式返回下列訊息:
content = web.decode('utf-8')
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa4 in position 95: inva
lid start byte
這個是不是換成我的library有問題嗎
※ 引述《timTan (用口頭禪區分年記)》之銘言:
※ 引述《bohan222 (哈哈哈)》之銘言:
: 請教大家
: Python 2.7.3 有使用下面utf-8的宣告
宣告是說你的程式碼是 utf8. 跟你要抓的東西無關。
: #!/usr/bin/python
: # -*- coding: utf-8 -*-
: 問題:
: 使用 web = urllib.urlopen(內容具有繁體中文的網站)
: content = web.read()
接下來的 content 只是一些無意義的 binary,
一定要解碼,不解碼,不能看。
而解碼的方式,推文已有。
編碼有學問
這篇 Joe 的文章一定要看過 http://bit.ly/14txdCm
: 想分析網頁內容為繁體的部分,結果繁體部分會變成亂碼,
: 似乎是ascii之類的編碼問題
: 想請教有人有遇過這類型問題嗎~謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.192.234.137
※ 編輯: timTan 來自: 123.192.234.137 (07/29 23:15)
→
07/29 23:16,
07/29 23:16
推
07/29 23:44,
07/29 23:44
→
07/29 23:45,
07/29 23:45
→
07/30 00:25,
07/30 00:25
推
07/30 00:36,
07/30 00:36
推
07/30 09:13,
07/30 09:13
→
07/30 09:48,
07/30 09:48
→
07/30 09:49,
07/30 09:49
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.43.211.213
→
07/30 22:48, , 1F
07/30 22:48, 1F
→
07/30 22:51, , 2F
07/30 22:51, 2F
→
07/30 22:53, , 3F
07/30 22:53, 3F
→
07/30 23:28, , 4F
07/30 23:28, 4F
推
07/30 23:32, , 5F
07/30 23:32, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):