gpt4 book ai didi

python - 当 Firefox 不是默认浏览器时,使用 Firefox 使用 Python 打开 HTML 文件

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:39 24 4
gpt4 key购买 nike

我已经看到一些与此相关的问题,但我仍然遇到问题。

运行代码:

>>>webbrowser.get('firefox')

错误:

webbrowser.Error: could not locate runnable browser

为了排除故障,我运行了:

>>>print(webbrowser._browser)

{'windows-default': [<class 'webbrowser.WindowsDefault'>, None], 'c:\\program files\\internet explorer\\iexplorer.exe': [None, <webbrowser.BackgroundBrowser object at 0x000000000651FEB8>]}

奇怪的是我安装了 Firefox,它是我的默认浏览器,而我试图通过 Python 打开的 HTML 文件却用 Firefox 打开。

除了我需要将此程序发送给可能已将 IE 设置为 Windows 默认设置的人,并且必须在 Firefox 中打开 HTML 文件之外,世界上一切都将是正确的。

最佳答案

All would be right with the world except I need to send this program out to people who likely have IE set as their Windows default, and the HTML file has to be opened in Firefox.

解决它的一种方法是使用 selenium 浏览器自动化包。你可以open local HTML files还有:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("file:///D:/folder/abcd.html")

关于python - 当 Firefox 不是默认浏览器时,使用 Firefox 使用 Python 打开 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37927327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com