[問題] UCS-2問題

看板Python作者 (TT)時間8年前 (2017/11/29 18:41), 8年前編輯推噓3(302)
留言5則, 3人參與, 8年前最新討論串1/1
小弟我正在練習爬蟲 遇到了這個問題 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

11/29 20:05, 8年前 , 1F
print(str(test).encode("utf8"))
11/29 20:05, 1F
我試了,結果跑出這個 https://imgur.com/a/Efl56

11/29 23:06, 8年前 , 2F
win10在powershell跑沒問題喔
11/29 23:06, 2F

11/29 23:06, 8年前 , 3F
可以Google commander encoding utf8
11/29 23:06, 3F

12/01 10:27, 8年前 , 4F
ok,我試試看
12/01 10:27, 4F
還是無法欸,不是出現本文中那張圖,就是上面那張 ※ 編輯: 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

12/01 19:58, 8年前 , 5F
這是可以的意思嗎?看起來沒問題
12/01 19:58, 5F
這是我截圖網頁的。我試了其他類似的網頁可以,唯獨這個網頁沒辦法,所以我懷疑是不是因為網頁的資料太多,中間插入了某些特殊符號,分割成幾個部分,才無法順利。 ※ 編輯: TingTT (59.127.5.98), 12/01/2017 21:09:28
文章代碼(AID): #1Q7exVYJ (Python)
文章代碼(AID): #1Q7exVYJ (Python)