简体   繁体   English

使用BeautifulSoup时遇到错误

[英]Encountering Error while using BeautifulSoup

I am trying to extract the words(verbs) starting with R from this page . 我试图从这个页面中提取以R开头的单词(动词)。 But on executing the following code: 但是在执行以下代码时:

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()

The Error thrown was something like this: 引发的错误是这样的:

UnicodeEncodeError: 'charmap' codec can't encode character u '\\xa9' in position 57801: character maps to undefined UnicodeEncodeError:'charmap'编解码器无法在位置57801中对字符u'\\ xa9'进行编码:字符映射为未定义

Can someone please tell me what the error is and how to fix and proceed? 有人可以告诉我错误是什么以及如何修复和继续?

It would be much easier if you showed us the whole stack trace or, at least, at which line it points. 如果您向我们展示了整个堆栈轨迹,或者至少向我们指出了它在哪一行,那会容易得多。

Anyway, I bet, the problem is with the last line. 无论如何,我敢打赌,问题出在最后一行。 Change it to: 将其更改为:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM