Karmic Coder
Karmic Coder

Reputation: 17949

Open IE Browser Window

The webbrowser library provides a convenient way to launch a URL with a browser window through the webbrowser.open() method. Numerous browser types are available, but there does not appear to be an explicit way to launch Internet Explorer when running python on windows.

WindowsDefault only works if Internet Explorer is set as the default browser, which is not an assumption I can make.

Is there a way to explicitly launch a URL into Internet Explorer without reverting to windows API calls?

Upvotes: 12

Views: 38615

Answers (7)

majumderS
majumderS

Reputation: 21

Please try putting the absolute path of internet explorer exe file in your code.

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

Upvotes: 1

C.H.S.
C.H.S.

Reputation: 370

More elegant code:

import webbrowser

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

Upvotes: 24

Kevin
Kevin

Reputation: 8561

You can always do something like

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

Upvotes: 4

Esteban Küber
Esteban Küber

Reputation: 36852

If you plan to use the script in more than your machine, keep in mind that not everyone has a English version of Windows

import subprocess
import os

subprocess.Popen(r'"' + os.environ["PROGRAMFILES"] + '\Internet Explorer\IEXPLORE.EXE" www.google.com')

Upvotes: 3

Lukáš Lalinský
Lukáš Lalinský

Reputation: 41316

iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
    "Internet Explorer\\IEXPLORE.EXE")
ie = webbrowser.BackgroundBrowser(iexplore)
ie.open(...)

This is what the webrowser module uses internally.

Upvotes: 8

SilentGhost
SilentGhost

Reputation: 319831

>>> ie = webbrowser.get('c:\\program files\\internet explorer\\iexplore.exe')
>>> ie.open('http://google.com')
True

Upvotes: 15

Mark
Mark

Reputation: 108557

The simplest way:

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

Upvotes: 3

Related Questions