在webbrowser
库提供通过推出一个浏览器窗口的URL的便捷方式webbrowser.open()
方法。 许多浏览器类型可供选择,但似乎没有要在Windows上运行的Python时启动Internet Explorer明确的方式。
WindowsDefault
如果Internet Explorer设置为默认浏览器,这不是一个假设,我可以做才有效。
有没有办法来明确启动URL到Internet Explorer中没有恢复到Windows API调用?
在webbrowser
库提供通过推出一个浏览器窗口的URL的便捷方式webbrowser.open()
方法。 许多浏览器类型可供选择,但似乎没有要在Windows上运行的Python时启动Internet Explorer明确的方式。
WindowsDefault
如果Internet Explorer设置为默认浏览器,这不是一个假设,我可以做才有效。
有没有办法来明确启动URL到Internet Explorer中没有恢复到Windows API调用?
更优雅的代码:
import webbrowser
ie = webbrowser.get(webbrowser.iexplore)
ie.open('google.com')
>>> ie = webbrowser.get('c:\\program files\\internet explorer\\iexplore.exe')
>>> ie.open('http://google.com')
True
iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
"Internet Explorer\\IEXPLORE.EXE")
ie = webbrowser.BackgroundBrowser(iexplore)
ie.open(...)
这就是webrowser
模块内部使用。
你总是可以这样做
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" http://www.example.com')
最简单的方法:
import subprocess
subprocess.Popen(r'"C:\Program Files\Internet Explorer\IEXPLORE.EXE" www.google.com')
如果你打算使用脚本比你的机器多,记住,不是每个人都有的Windows英文版
import subprocess
import os
subprocess.Popen(r'"' + os.environ["PROGRAMFILES"] + '\Internet Explorer\IEXPLORE.EXE" www.google.com')
请尝试将Internet Explorer中的exe文件的绝对路径在你的代码。
ie=webbrowser.get("C:\Program Files\Internet Explorer\iexplore.exe")
ie.open_new("http://google.com")