【发布时间】: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