0
從Jupyter IPython的筆記本電腦運行時,下面的代碼工作正常:BeautifulSoup代碼在IPython的筆記本電腦,但不蝕
from bs4 import BeautifulSoup
xml_file_path = "<Path to XML file>"
s = BeautifulSoup(open(xml_file_path), "xml")
但在Eclipse/PyDev的(使用相同的Python運行時產生的湯時失敗解釋器):
Traceback (most recent call last):
File "~/parser/scratch.py", line 3, in <module>
s = BeautifulSoup(open(xml_file), "xml")
File "/anaconda/lib/python3.5/site-packages/bs4/__init__.py", line 175, in __init__
markup = markup.read()
File "/anaconda/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 1812: ordinal not in range(128)
- Python版本:3.5.2(阿納康達4.1.1)
- BeautifulSoup:版本4
- IPython的筆記本版本:4.2.1
- Eclipse版本:Mars.2版本(4.5.2)
- PyDev的版本:5.1.2.20160623256
- 的Mac OS X:埃爾卡皮坦10.11.6
更新: 在Eclipse中導致問題的文件中的字符是�
,但這不會導致IPython Notebook中出現問題!如果我從XML文件中刪除這個字符,那麼代碼在Eclipse中也能正常工作。在Eclipse中是否有一些設置需要更改,以便代碼不會在此(也可能是其他此類)字符上失敗?
[UnicodeDecodeError:'ascii'編解碼器無法解碼位置1中的字節0xef](http://stackoverflow.com/questions/10561923/unicodedecodeerror-ascii-codec-cant-decode-byte-0xef- in-position-1) – DyZ
@DYZ - 這裏沒有打印。它發生在我創造湯時。 – arun
您是否試過'open(xml_file_path,「utf-8」)'? –