gpt4 book ai didi

python - 使用 BeautifulSoup 时遇到错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:19:03 25 4
gpt4 key购买 nike

我正在尝试从 this page 中提取以 R 开头的单词(动词) .但是在执行以下代码时:

from bs4 import BeautifulSoup
import urllib2
url = "http://www.usingenglish.com/reference/phrasal-verbs/r.html"
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content)
print soup.prettify()

抛出的错误是这样的:

UnicodeEncodeError: 'charmap' codec can't encode character u '\xa9' in position 57801: character maps to undefined

有人可以告诉我错误是什么以及如何修复和继续吗?

最佳答案

如果您向我们展示整个堆栈跟踪,或者至少,它指向哪一行,那将会容易得多。

无论如何,我敢打赌,问题出在最后一行。将其更改为:

print(soup.prettify().encode('utf-8'))

关于python - 使用 BeautifulSoup 时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17060930/

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