IPython.core.display无法按预期工作

时间:2016-01-23 19:00:14

标签: python python-2.7 beautifulsoup ipython

我一直在尝试通过哈佛大学的Python入门数据科学课程和其中一个实验室,我遇到了输出问题。

我正在使用Spyder和anaconda启动器并使用Python 2.7。这是我正在使用的代码:

from IPython.core.display import HTML
import requests
import bs4

req = requests.get("https://en.wikipedia.org/wiki/Harvard_University")
page = req.text 

## req.text gives us the HTML code for the page 

soup = bs4.BeautifulSoup(page, 'html.parser')


## List comprehensions

[t["class"] for t in soup.find_all("table") if t.get("class")]


my_list = []
for t in soup.find_all("table"):
    if t.get("class"):
        my_list.append(t['class'])

table_html = str(soup.find("table", "wikitable"))

test = HTML(table_html)

测试应该产生这样的结果:What it should look like

相反,我只是在控制台中得到这个:

<IPython.core.display.HTML object>

我使用的是python 2.7还是我错过了更多的东西?

0 个答案:

没有答案
相关问题