Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IPython.core.display未按预期工作_Python_Python 2.7_Beautifulsoup_Ipython - Fatal编程技术网

IPython.core.display未按预期工作

IPython.core.display未按预期工作,python,python-2.7,beautifulsoup,ipython,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.tex

我一直在努力学习哈佛大学的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)
测试应产生如下结果:

相反,我只是在控制台中获取以下信息:

<IPython.core.display.HTML object>


是我在使用Python2.7,还是我遗漏了更多东西

哪个控制台?如果您使用的是带有
ipython
的简单终端,那么这种输出是不可能的。您需要使用
qtconsole
notebook
前端(spyder中可能包含该前端,但我不确定)。尝试打开Spyder外部的
qtconsole
,查看是否获得所需的输出。如果是的话,你必须确保Spyder确实支持它,如果是的话,如果有一些设置正在禁用它。@Bakuriu非常感谢你。他们的工作很完美。看来我现在会更频繁地使用jupyter。