print soup.prettify产生空白输出

时间:2016-09-17 15:12:26

标签: python-2.7 anaconda

我已尝试以下代码来提取页面网址。

 from bs4 import BeautifulSoup
 import urllib3

 http = urllib3.PoolManager()

 url = 'http://www.thefamouspeople.com/singers.php'
 response = http.request('GET', url)
 html = response.read()
 soup = BeautifulSoup(html)


 print soup.prettify()

但是,我想知道它给出空白输出。我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

您应该尝试在html = str(html)之后添加html = response.read(),因为html = response.read()会返回字节。