Webbrowser Module
suggest changeIntroduction
According to Python’s standard documentation, the webbrowser module provides a high-level interface to allow displaying Web-based documents to users. This topic explains and demonstrates proper usage of the webbrowser module.
Syntax
webbrowser.open(url, new=0, autoraise=True)webbrowser.open_new(url)webbrowser.open_new_tab(url)webbrowser.get(using=None)webbrowser.register(name, constructor, instance=None)
Parameters
| Parameter | Details |
|---|---|
webbrowser.open() |
|
| url | the URL to open in the web browser |
| new | 0 opens the URL in the same browser window if possible, 1 opens a new window, 2 opens a new tab |
| autoraise | if set to True, the window is raised if possible. The default is True. |
webbrowser.open_new() |
|
| url | the URL to open in the web browser |
webbrowser.open_new_tab() |
|
| url | the URL to open in the web browser |
webbrowser.get() |
|
| using | the browser to use |
webbrowser.register() |
|
| name | browser name |
| constructor | a class used to build the controller, or None when instance is passed. It is not a filesystem path (help). |
| instance | An instance of a web browser returned from the webbrowser.get() method |
Remarks
The following table lists predefined browser types. The left column are names that can be passed into the webbrowser.get() method and the right column lists the class names for each browser type.
| Type Name | Class Name |
|---|---|
'mozilla' |
Mozilla('mozilla') |
'firefox' |
Mozilla('mozilla') |
'netscape' |
Mozilla('netscape') |
'galeon' |
Galeon('galeon') |
'epiphany' |
Galeon('epiphany') |
'skipstone' |
BackgroundBrowser('skipstone') |
'kfmclient' |
Konqueror() |
'konqueror' |
Konqueror() |
'kfm' |
Konqueror() |
'mosaic' |
BackgroundBrowser('mosaic') |
'opera' |
Opera() |
'grail' |
Grail() |
'links' |
GenericBrowser('links') |
'elinks' |
Elinks('elinks') |
'lynx' |
GenericBrowser('lynx') |
'w3m' |
GenericBrowser('w3m') |
'windows-default' |
WindowsDefault |
'macosx' |
MacOSX('default') |
'safari' |
MacOSX('safari') |
'google-chrome' |
Chrome('google-chrome') |
'chrome' |
Chrome('chrome') |
'chromium' |
Chromium('chromium') |
'chromium-browser' |
Chromium('chromium-browser') |
This table is an older snapshot. Python 3.14 registers a name only when that executable is found. It does not register galeon, skipstone, netscape, mosaic, or grail. When firefox is on PATH, the controller is Mozilla("firefox"), not Mozilla("mozilla").
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents