如何在使用Python单击HTML页面上的某个链接时打开一个Windows文件夹 [英] How to open a windows folder when clicking on some link on a HTML page using Python

查看:173
本文介绍了如何在使用Python单击HTML页面上的某个链接时打开一个Windows文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写下面的程序:

  *** import os 
filepath = r'C:\ TestData \openfolder.html'
abc = open(filepath,'w')
abc.writelines('< html>< head>< / head>< body>')
$ b $ abc.writelines('< a href =os.startfile(filepath)> First Link< / a> \\\
')

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

我想要做什么是如果我点击浏览器上的第一个链接,我应该可以打开文件夹路径为Filepath。 os.startfile完美的打开文件夹,但我不知道如何实现这个里面的一些链接。
谢谢。

解决方案

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

 < a href =file:/// C:/TestData/openfolder.html>链接至测试数据< / a> 

这里是关于在Windows中使用文件URI的文章



< UPD(从注释中提取):每个浏览器都有自己的方式来处理这样的URL。至少在Windows 7下的Internet Explorer 8打开Windows资源管理器中的链接,就像jags所要求的一样。

最后,对于动态页面 web服务器是必需的。如果需要,请查看关于创建简单Web服务的讨论使用python


I am writing following program :

***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>')***

What I want to do is if I click First Link on a browser, I should be able to open the folder having path as "Filepath". os.startfile works perfect for opening a folder but I don't know how to implement this inside some link. Thanks.

解决方案

Try to use URI with file: scheme like file:///C:/TestData/openfolder.html in your html:

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

Here is article on using file URIs in Windows.

UPD (extraction from comments): Each browser has its own way to handle such urls. At least Internet Explorer 8 under Windows 7 opens links in Windows Explorer as was required by jags.

Finally, for dynamic pages the web server is required. If one is needed take a look at discussion on creating simple web services using python.

这篇关于如何在使用Python单击HTML页面上的某个链接时打开一个Windows文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆