簡體   English   中英

使用BeautifulSoup時遇到錯誤

[英]Encountering Error while using BeautifulSoup

我試圖從這個頁面中提取以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'編解碼器無法在位置57801中對字符u'\\ xa9'進行編碼:字符映射為未定義

有人可以告訴我錯誤是什么以及如何修復和繼續?

如果您向我們展示了整個堆棧軌跡,或者至少向我們指出了它在哪一行,那會容易得多。

無論如何,我敢打賭,問題出在最后一行。 將其更改為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM