gpt4 book ai didi

python UnicodeEncodeError > 我怎样才能简单地删除麻烦的 unicode 字符?

转载 作者:太空狗 更新时间:2023-10-29 22:11:54 26 4
gpt4 key购买 nike

这是我做的..

>>> soup = BeautifulSoup (html)
>>> soup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 96953: ordinal not in range(128)
>>>
>>> soup.find('div')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 11035: ordinal not in range(128)
>>>
>>> soup.find('span')
<span id="navLogoPrimary" class="navSprite"><span>amazon.com</span></span>
>>>

我怎样才能简单地从 html 中删除麻烦的 unicode 字符?
或者有没有更清洁的解决方案?

最佳答案

试试这个方法:soup = BeautifulSoup (html.decode('utf-8', 'ignore'))

关于python UnicodeEncodeError > 我怎样才能简单地删除麻烦的 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5236437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com