【问题标题】:Creating a file which links to a Website in Python在 Python 中创建一个链接到网站的文件
【发布时间】:2023-03-13 19:31:01
【问题描述】:

我正在处理一个 python 脚本,它必须创建一个文件,在最好的情况下,应该是双击打开例如 IE 然后加载这个网站。我已经通过 SO 和 Google 进行了搜索,但我没有找到任何东西。你们有什么想法我怎么能意识到这一点?

到目前为止

【问题讨论】:

  • 你可以让你的“文件”成为一个 shell/bash 脚本,当运行/点击时会打开一个浏览器
  • 这种解决方法暂时搁置,如果可以避免的话,我不想要另一个脚本
  • 那么您能否让脚本输出一个 *.html 文件,由于扩展规则,该文件会在用户选择的浏览器中打开?

标签: python-2.7 hyperlink


【解决方案1】:

您需要pip install winshell 在您的桌面上创建一个 .url 快捷方式;

import os, winshell

desktop = winshell.desktop()
path = os.path.join(desktop, "google.url")
target = "www.google.com/"
shortcut = file(path, 'w')
shortcut.write('[InternetShortcut]\n')
shortcut.write('URL=%s' % target)
shortcut.close()

Using Python to Create Shortcuts

【讨论】:

    猜你喜欢
    • 2018-09-15
    • 2017-03-10
    • 2013-08-05
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 2015-07-23
    相关资源
    最近更新 更多