在IPython Notebook中无法渲染iframe

18
以下的 iframe 将无法在 ipython-notebook 中显示。
from IPython.display import HTML
HTML('<iframe src=http://stackoverflow.com width=700 height=350></iframe>')

但是,这个将被渲染(注意,.com和.org的区别)

from IPython.display import HTML
HTML('<iframe src=http://stackoverflow.org width=700 height=350></iframe>')

在第一个例子中,我做错了什么吗?如果这是一个 bug,我应该去哪里提交 bug 报告?


也许使用IPython显示中的IFrame对象会起作用... - Matt
4个回答

40

IPython 现在直接支持 IFrame:

from IPython.display import IFrame
IFrame('http://stackoverflow.org', width=700, height=350)

了解更多IPython嵌入式内容,请查看此IPython笔记本。


1
这个链接在这里与原始链接看起来很相似。 - Wayne

10

你在javascript控制台看到了"Refused to display document because display forbidden by X-Frame-Options."的提示。一些网站明确拒绝在iframe中显示。


1

通过修改url以使用https,我能够在我的笔记本服务器上嵌入一些iframe。

from IPython.display import VimeoVideo
v = VimeoVideo(id='53051817', width=800, height=600)
print v.src
>>> 'http://player.vimeo.com/video/53051817'
v.src = v.src.replace('http','https')
v

0

使用 %%html 魔法单元格命令:

%%html
<iframe width="700" height="500" src="https://www.youtube.com/embed/r0Ogt-q956I" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接