使用 html.parser 的 Beautiful Soup 在解码引号时遇到问题

Beautiful Soup using html.parser having troubles decoding quotation marks

我有一个简单的程序可以从 Fox News 抓取一篇文章的文本,但出于某种原因,我无法正确解码引号。

from bs4 import BeautifulSoup
import urllib

r = urllib.urlopen('http://www.foxnews.com/politics/2016/10/14/emails-reveal-clinton-teams-early-plan-for-handling-bill-sex-scandals.html').read()
soup = BeautifulSoup(r, 'html.parser')

for item in soup.find_all('div', class_='article-text'):
    print item.get_text().encode('UTF-8')

这抓住了我正在寻找的文本,但文章中几乎所有的引号都是这样打印的:比尔·克林顿 (Bill Clinton) 的。我已经尝试专门将解码定义为 utf-8,并查看了页面以查看它声明的编码,它也是 utf-8,所以我不确定为什么会这样。

所以这并不能解决为什么 Beautiful Soup 在解码文本时遇到问题,但我找到了两种迂回的方法来解决这个问题。一种是在脚本的顶部声明一个编码:

      # This Python file uses the following encoding: utf-8

另一种是解码并删除所有Unicode字符,然后用ascii重新编码。

print(temp.decode('unicode_escape').encode('ascii','ignore'))