看板 Python 關於我們 聯絡資訊
想請教各位高手 我有個input.txt 我很確定他是用utf-8儲存的 但是用以下的beautiful soup 處理 strip tag 卻還是亂碼 想請問是不是哪裡寫錯了 謝謝 import requests from bs4 import BeautifulSoup res = requests.get('http://localhost/input.txt',verify=False) obj=bytes(res.text, "utf-8") UTF8str=obj.decode('utf-8', 'ignore') soup = BeautifulSoup(UTF8str, "html.parser") text = soup.getText() print(text) 但是出來 還是亂碼 我是照著書打的 實在不知道問題出在哪 感謝各位高手 ....orz -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.217.14.99 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1472565827.A.D8A.html
Neverfor: 討厭win10記事本 08/30 22:19
※ 編輯: imimi (180.217.14.99), 08/30/2016 22:26:02
enjoyloli: #-*- coding: utf-8 -*- 有用嗎? 08/31 00:07
uranusjr: 既然文字內容就是 UTF-8, 你為什麼要 encode 又 decode 08/31 05:50
uranusjr: 直接把 res.text 拿去 parse 不就好了? 08/31 05:50
imimi: 感謝感謝~~ 理解了~~~ 03/10 17:39