看板 Python 關於我們 聯絡資訊
小弟我正在練習爬蟲 遇到了這個問題 https://imgur.com/a/q7Kop 網路上說是Python編碼無法映射奇怪的符號 可是我看了看原始碼,怎麼也看不出有奇怪符號 import json from urllib.request import urlopen with urlopen("https://pm25.lass-net.org/data/last-all-airbox.json") as url: text = url.read().decode("utf8") test = json.loads(text) print(test) 附上我的code 請問要如何改才能順利輸出? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.79.197 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1511952095.A.893.html
cutekid: print(str(test).encode("utf8")) 11/29 20:05
我試了,結果跑出這個 https://imgur.com/a/Efl56
TitanEric: win10在powershell跑沒問題喔 11/29 23:06
TitanEric: 可以Google commander encoding utf8 11/29 23:06
TingTT: ok,我試試看 12/01 10:27
還是無法欸,不是出現本文中那張圖,就是上面那張 ※ 編輯: TingTT (140.116.79.197), 12/01/2017 13:22:22 不知道是不是因為這個,一整段原始碼被分成好幾個部分 https://imgur.com/a/KduL3 ※ 編輯: TingTT (140.116.79.197), 12/01/2017 13:33:39
TitanEric: 這是可以的意思嗎?看起來沒問題 12/01 19:58
這是我截圖網頁的。我試了其他類似的網頁可以,唯獨這個網頁沒辦法,所以我懷疑是不是因為網頁的資料太多,中間插入了某些特殊符號,分割成幾個部分,才無法順利。 ※ 編輯: TingTT (59.127.5.98), 12/01/2017 21:09:28