[问题] 中文编码问题

楼主: vidmle (tt)   2017-11-27 17:30:33
大家好,最近刚学Python,用的版本是Python3.4
在爬虫过程中,遇到编码问题
此为原始码
https://imgur.com/a/mMhKs
我的程式
from selenium import webdriver
from bs4 import BeautifulSoup
from urllib.request import urlopen
import sys
import re
import json
driver =
webdriver.PhantomJS
(executable_path=r'C:\Python34\phantomjs-2.1.1-windows\bin\phantomjs')
#上述三行为同一行
driver.get("http://opendata2.epa.gov.tw/AQI.json")
pageSource = driver.page_source
bsObj = BeautifulSoup(pageSource, "html.parser")
AQIScript = str(bsObj.html.body.find(text=re.compile("AQI")))
print(AQIScript)
输出后中文字会乱码,请问该如何解决?
https://imgur.com/a/auAuO
最终目的是要将AQIScript丢进json再上传至SQL
→ 我的程式码 js = json.loads(AQIScript)
之前有试过编码是\uXXXX的没问题可以成功显示中文
这是另一个网站的(此输出经过json.loads之后上传至SQL为正常中文显示)
https://imgur.com/a/bEsJZ
请教各位高手,我要怎么改才能解决乱码的问题呢?
感谢~~
作者: HenryLiKing (HenryLiKing)   2017-11-27 20:08:00
我放到json里面也会这样欸QAQ
作者: TitanEric (泰坦)   2017-11-27 22:43:00
嗨 请参考下面连结https://goo.gl/WbEMS6
楼主: vidmle (tt)   2017-11-28 11:03:00
谢谢你,已成功解决

Links booklink

Contact Us: admin [ a t ] ucptt.com