Python報UnicodeDecodeError
在進行開啟檔案過程中,提示UnicodeDecodeError錯誤,這可能是Python嘗試用gbk編碼開啟一個非gbk編碼的檔案(Windows下Python預設使用gbk讀取檔案)導致。
解決:
在開啟時指定編碼。
報錯語句:
soup = BeautifulSoup(open(“c:\\user\desktop\sina.html”))
修改後:
soup = BeautifulSoup(open(“c:\\user\desktop\sina.html”,encoding="utf-8"))
注:上述中"\U"是轉義字元,如果直接是c:\user...則會提示SyntaxError,這時我們就需要多加一個“\”
相關文章
- Python報錯:UnicodeDecodeError: 'gbk' codec can't decode byte ...PythonUnicodeError
- 如何理解 python UnicodeEncodeError 和 UnicodeDecodeError :python 的 string 和 unicodePythonUnicodeError
- Python3.7使用pip install xxxx報錯:UnicodeDecodeError: 'gbk' codec can't decode bytePythonUnicodeError
- Django2.2 報錯:UnicodeDecodeError 解決方法DjangoUnicodeError
- 【廖雪峰python入門筆記】Unicode編碼_UnicodeDecodeError處理Python筆記UnicodeError
- pip install ... ERROR: UnicodeDecodeError: ‘gbk‘ codec can‘t decode/ python setup.py egg_info CheckErrorUnicodePython
- python在用pandas對csv檔案處理的時候報UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb6。。。的錯誤PythonUnicodeError
- Python讀取csv檔案出現解碼錯誤UnicodeDecodeError: ‘utf-8‘ codec can‘t decodPythonUnicodeError
- Python讀取檔案時出現UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解決方案PythonUnicodeError
- python的報錯Python
- pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in positionErrorUnicode
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byteUnicodeError
- 38. 報數(python)Python
- Python報錯總結Python
- python-pycharm報錯PythonPyCharm
- python分析文字報告Python
- 【python 監控報警】python自動發微信監控報警Python
- python3 print報錯Python
- Linux:Python報錯:No module named MySQLdbLinuxPythonMySql
- python (pip)安裝talib報錯Python
- python值得報班學習嗎Python
- Vue安裝依賴報錯:checking for Python executable "python" in the PATHVuePython
- Python釘釘報警及Zabbix整合釘釘報警Python
- python報名系統抗壓測試Python
- python virtualenv報錯-bash: virtualenv: command not foundPython
- Python 入門級報錯處理Python
- python實現報表用什麼?Python
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- python3升級後的報錯Python
- Python筆記-CSP 201912-1 報數Python筆記
- Python分析3月政府工作報告Python
- Python 實現自動化 Excel 報表PythonExcel
- python requests.post Max retries exceeded with url 報錯Python
- Python 執行報錯 PermissionError: [Errno 13] Permission denied: '***.***'PythonError
- 日常python報錯及解決方法記錄Python
- matplotlib使用時報錯RuntimeError: Python is not installed as a framework(一)ErrorPythonFramework
- python 3呼叫paramiko模組報錯AttributeError: modulePythonError
- 系統巡檢Python生成word報告🧫Python