2
我想從this page中提取以R開頭的單詞(動詞)。但在執行以下代碼:使用BeautifulSoup時遇到錯誤
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
有人能告訴我什麼錯誤,以及如何解決並繼續?
謝謝!這就像一個魅力!另一個問題:是否有任何方法將錯誤(Traceback)寫入文件以便可以輕鬆共享? (否則唯一的選擇是鍵入整個事物!) –
@RakshithNayak熟悉['logging'](http://docs.python.org/2/library/logging.html)可能是一個好主意。一旦你花了一個小時仔細探索它的能力,真的讓生活更輕鬆。 – kirelagin