作者TingTT (TT)
看板Python
标题[问题] UCS-2问题
时间Wed Nov 29 18:41:31 2017
小弟我正在练习爬虫
遇到了这个问题
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://webptt.com/cn.aspx?n=bbs/Python/M.1511952095.A.893.html
1F:推 cutekid: print(str(test).encode("utf8")) 11/29 20:05
我试了,结果跑出这个
https://imgur.com/a/Efl56
2F:推 TitanEric: win10在powershell跑没问题喔 11/29 23:06
3F:→ TitanEric: 可以Google commander encoding utf8 11/29 23:06
4F:→ 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
5F:推 TitanEric: 这是可以的意思吗?看起来没问题 12/01 19:58
这是我截图网页的。我试了其他类似的网页可以,唯独这个网页没办法,所以我怀疑是不是因为网页的资料太多,中间插入了某些特殊符号,分割成几个部分,才无法顺利。
※ 编辑: TingTT (59.127.5.98), 12/01/2017 21:09:28