【问题标题】:Download HTML file from jupyter-notebook to local从 jupyter-notebook 下载 HTML 文件到本地
【发布时间】:2021-11-21 07:22:41
【问题描述】:

如何使用给定的弹出链接从 jupyter-notebook 下载文件?我需要这个弹出链接并单击它以将其下载为 HTML 文件。我遇到了字符" 双引号和' 的问题,这些字符对我的HTML 代码造成了麻烦,以便使其弹出下载。但是,我需要这些字符将其保留在我的脚本中,而不需要替换任何内容。

这是我的 HTML 脚本:

<html>
<head><meta charset='utf-8' /></head>
<body>
<h3>You can "view" HTML code "in" notebooks. Result 'want to' get it '"' testing only</h3>
</body>
</html>

这是我的代码 python 脚本:

from IPython.display import FileLink, HTML

title = "Download HTML file"
filename = "data.html"

payload = open("./cobaan_html2.html").read()
payload = payload.replace('<meta charset="utf-8" />', "<meta charset='utf-8' />")
html = '<a download="{filename}" href="data:text/html;charset=utf-8,'+payload+'" target="_blank">{title}</a>'

print(payload)
HTML(html)

这就是我得到的。

<html>
<head><meta charset="utf-8" /></head>
<body>
<h3>You can "view" HTML code "in" notebooks. Result 'want to' get it '"' testing only</h3>
</body>
</html>
You can "view" HTML code "in" notebooks. Result 'want to' get it '"' testing only
" target="_blank">{title}

用图片结果证明:

【问题讨论】:

    标签: python html utf-8 jupyter-notebook


    【解决方案1】:

    尝试将引号替换为它们的非破坏性 HTML 等效项,如下所示:

    1. " --> &amp;quot;
    2. ' --> &amp;apos;

    【讨论】:

      猜你喜欢
      • 2021-10-27
      • 2020-05-17
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2020-08-10
      • 2018-10-18
      相关资源
      最近更新 更多