BeautifulSoup解析特殊字符

时间:2016-11-10 10:32:57

标签: python-2.7 beautifulsoup

我从BeautifulSoup的链接中提取文本,如:

from BeautifulSoup import BeautifulSoup
import urllib2
 response = urllib2.urlopen(link)
 html = response.read()
 soup = BeautifulSoup(html)

 #print(soup)
 for a in soup.findAll('a',attrs={"class":"link"}):
  print(a.text)

但是我为一个简单的“&#8211”获得了一些像“-”这样的字符。 如何让这些人物对人类可读?

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

for a in soup.findAll('a',attrs={"class":"link"}):
  print(a.get_text())