[問題] 中文編碼問題
大家好,最近剛學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
請教各位高手,我要怎麼改才能解決亂碼的問題呢?
感謝~~
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.79.197
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1511775036.A.CA4.html
推
11/27 20:08,
7年前
, 1F
11/27 20:08, 1F
推
11/27 22:43,
7年前
, 2F
11/27 22:43, 2F
→
11/27 22:43,
7年前
, 3F
11/27 22:43, 3F
→
11/28 11:03,
7年前
, 4F
11/28 11:03, 4F
討論串 (同標題文章)
Python 近期熱門文章
PTT數位生活區 即時熱門文章