[問題] requests 撈回來的 big5 網頁轉成 utf8
https://gist.github.com/anonymous/f7781da21b44925a36320e61b6f27283
print h.text # 亂碼
我範例是從露天拍賣抓資料可是出現都是亂碼, 後來google 有人提到露天網頁編碼是 big5
後來我找到有人針對露天拍賣編碼去轉成unicode
http://bugcaptor.logdown.com/posts/181043-the-big5-page-requests-get-back-into-python-utf8
b = h.text.encode('latin-1').decode('big5')
UnicodeDecodeError: 'big5' codec can't decode bytes in position 207-208:
illegal multibyte sequence
但會出現上面錯誤訊息
後來我改成utf-8 網頁資料就正常
b = h.text.encode('latin-1').decode('utf-8')
好奇露天拍路編碼是 big5 那為什麼用 latin-1 轉成 str 在用decode('utf-8') 轉回 unicode
這樣會是正確?
print h.encoding 想去看編碼可是看到編碼是 ISO-8859-1 怎麼跟big5 utf8 latin-1 都沒關係?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.180.117.245
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1477122558.A.2AF.html
※ 編輯: yshihyu (175.180.117.245), 10/22/2016 15:53:19
→
10/22 16:10, , 1F
10/22 16:10, 1F
→
10/22 16:10, , 2F
10/22 16:10, 2F
→
10/22 16:16, , 3F
10/22 16:16, 3F
→
10/22 16:30, , 4F
10/22 16:30, 4F
→
10/22 16:40, , 5F
10/22 16:40, 5F
→
10/22 16:40, , 6F
10/22 16:40, 6F
→
10/22 17:40, , 7F
10/22 17:40, 7F
→
10/22 17:41, , 8F
10/22 17:41, 8F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章
16
24