11.1 webbrowser -- Convenient Web-browser controller

Python PEP

11.1 webbrowser -- Convenient Web-browser controller

The webbrowser module provides a very high-level interface to allow displaying Web-based documents to users. The controller objects are easy to use and are platform-independent. Under most circumstances, simply calling the open() function from this module will do the right thing.

Under Unix, graphical browsers are preferred under X11, but text-mode browsers will be used if graphical browsers are not available or an X11 display isn't available. If text-mode browsers are used, the calling process will block until the user exits the browser.

Under Unix, if the environment variable BROWSER exists, it is interpreted to override the platform default list of browsers, as a colon-separated list of browsers to try in order. When the value of a list part contains the string %s, then it is interpreted as a literal browser command line to be used with the argument URL substituted for the %s; if the part does not contain %s, it is simply interpreted as the name of the browser to launch.

For non-Unix platforms, or when X11 browsers are available on Unix, the controlling process will not wait for the user to finish with the browser, but allow the browser to maintain its own window on the display.

The following exception is defined:

Exception raised when a browser control error occurs.

The following functions are defined:

Display url using the default browser. If new is true, a new browser window is opened if possible. If autoraise is true, the window is raised if possible (note that under many window managers this will occur regardless of the setting of this variable).

Open url in a new window of the default browser, if possible, otherwise, open url in the only browser window.

Return a controller object for the browser type name. If name is empty, return a controller for a default browser appropriate to the caller's environment.

Register the browser type name. Once a browser type is registered, the get() function can return a controller for that browser type. If instance is not provided, or is None, constructor will be called without parameters to create an instance when needed. If instance is provided, constructor will never be called, and may be None.

This entry point is only useful if you plan to either set the BROWSER variable or call get with a nonempty argument matching the name of a handler you declare.

A number of browser types are predefined. This table gives the type names that may be passed to the get() function and the corresponding instantiations for the controller classes, all defined in this module.

Type Name Class Name Notes
'mozilla' Netscape('mozilla')
'netscape' Netscape('netscape')
'mosaic' GenericBrowser('mosaic %s &')
'kfm' Konqueror() (1)
'grail' Grail()
'links' GenericBrowser('links %s')
'lynx' GenericBrowser('lynx %s')
'w3m' GenericBrowser('w3m %s')
'windows-default' WindowsDefault (2)
'internet-config' InternetConfig (3)

Notes:

``Konqueror'' is the file manager for the KDE desktop environment for UNIX, and only makes sense to use if KDE is running. Some way of reliably detecting KDE would be nice; the KDEDIR variable is not sufficient. Note also that the name ``kfm'' is used even when using the konqueror command with KDE 2 -- the implementation selects the best strategy for running Konqueror.

Only on Windows platforms; requires the common extension modules win32api and win32con.

Only on MacOS platforms; requires the standard MacPython ic module, described in the Macintosh Library Modules manual.


See About this document... for information on suggesting changes.