html - 使用 Python 单击 HTML 页面上的某些链接时如何打开 Windows 文件夹

标签 html windows internet-explorer firefox google-chrome

我正在编写以下程序:

***import os
filepath=r'C:\TestData\openfolder.html'
abc=open(filepath,'w')
abc.writelines('<html><head></head><body>')

abc.writelines('<a href="os.startfile(filepath)">First Link</a>\n')

abc.writelines('</body></html>')***

我想要做的是,如果我在浏览器上单击第一个链接,我应该能够打开路径为“文件路径”的文件夹。 os.startfile 非常适合打开文件夹,但我不知道如何在某些链接中实现它。 谢谢。

最佳答案

尝试将 URI 与 file: 方案一起使用,如 file:///C:/TestData/openfolder.html 在您的 html 中:

<a href="file:///C:/TestData/openfolder.html">Link to test data</a>

这里是 article on using file URIs in Windows .

UPD(从评论中提取):每个浏览器都有自己的方式来处理此类 url。至少 Windows 7 下的 Internet Explorer 8 会按照 jags 的要求在 Windows 资源管理器中打开链接。

最后,对于动态页面 web server是必须的。如果需要,请查看 discussion on creating simple web services using python .

关于html - 使用 Python 单击 HTML 页面上的某些链接时如何打开 Windows 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11806853/

相关文章:

html - 如何动态改变顶部菜单的背景颜色?

ios - 如何在不同分辨率的不同设备上使用图像?

windows - Windows x86 堆栈中的堆栈是如何定义的?

c# - 无法注册 Windows.Devices.Bluetooth

javascript - IE 给出 “Function expected” 错误

javascript - 在 JavaScript 中测量文本大小

c++ - 管道在 Windows 7 上的 WinApi 中不起作用,但在 Windows 10 上起作用

internet-explorer - IE10 和 flexbox 的问题——2012 年 3 月的草案不起作用?

javascript - 在 Internet Explorer 中递归图像延迟加载失败(6-8)

iphone - 移动浏览器显示的 CSS 问题 (iPhone)