Python 打开IE浏览器窗口

Python 打开IE浏览器窗口,python,internet-explorer,browser,Python,Internet Explorer,Browser,提供了通过webbrowser.open()方法通过浏览器窗口启动URL的便捷方法。可以使用多种浏览器类型,但在windows上运行python时,似乎没有明确的方式启动Internet Explorer WindowsDefault仅当Internet Explorer设置为默认浏览器时才起作用,这不是我的假设 有没有一种方法可以在不返回windows API调用的情况下将URL显式启动到Internet Explorer中 最简单的方法: import subprocess subproce

提供了通过
webbrowser.open()
方法通过浏览器窗口启动URL的便捷方法。可以使用多种浏览器类型,但在windows上运行python时,似乎没有明确的方式启动Internet Explorer

WindowsDefault
仅当Internet Explorer设置为默认浏览器时才起作用,这不是我的假设

有没有一种方法可以在不返回windows API调用的情况下将URL显式启动到Internet Explorer中

最简单的方法:

import subprocess
subprocess.Popen(r'"C:\Program Files\Internet Explorer\IEXPLORE.EXE" www.google.com')

你总是可以做这样的事情

subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" http://www.example.com')

这就是
webrowser
模块内部使用的内容。

如果您计划在多台计算机上使用该脚本,请记住并非每个人都有英文版本的Windows

import subprocess
import os

subprocess.Popen(r'"' + os.environ["PROGRAMFILES"] + '\Internet Explorer\IEXPLORE.EXE" www.google.com')
更优雅的代码:

import webbrowser

ie = webbrowser.get(webbrowser.iexplore)
ie.open('google.com')

请尝试将internet explorer exe文件的绝对路径放入代码中

ie=webbrowser.get("C:\Program Files\Internet Explorer\iexplore.exe")
ie.open_new("http://google.com") 

请记住,Windows的非英语版本将其
程序文件
文件夹命名为不同的名称
Archivos de Programa
,例如西班牙语。您应该改用
%PROGRAMFILES%
。您需要启动IE的原因是什么?我正在启动的页面是本地ms office生成的html文件,它使用了可怕的标记,只有IE才能正确理解。这将是一个内部脚本,所以用户自主性不是问题。我一直得到“错误:找不到可运行浏览器”在后台不起作用。它总是打开页面。事实上,我试过做ie.Visible=0仍然不起作用。
import webbrowser

ie = webbrowser.get(webbrowser.iexplore)
ie.open('google.com')
ie=webbrowser.get("C:\Program Files\Internet Explorer\iexplore.exe")
ie.open_new("http://google.com")