IPython.core.display未按预期工作
我一直在努力学习哈佛大学的Python入门数据科学课程,在其中一个实验室,我遇到了一个输出问题 我将Spyder与anaconda启动器一起使用,并使用Python 2.7。这是我正在使用的代码: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
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。