Python webbrowser Module
Example
Open a URL in the default web browser:
import webbrowser
webbrowser.open('https://www.w3schools.com')
print('Browser opened!')
Try it Yourself »
Definition and Usage
The webbrowser module provides a high-level interface to display web-based documents to users in their default browser.
Use it to open URLs in a browser window, open new tabs or windows, or access specific browsers installed on the system.
Note: The module attempts to locate and use the default web browser. On graphical systems, it will launch the browser in a window.
Members
| Member | Description |
|---|---|
| BackgroundBrowser | Controller for browsers that run in the background without blocking Python. |
| BaseBrowser | Parent class that all browser controllers inherit from. |
| Chrome | Controller specifically for Google Chrome and Chromium browsers. |
| Chromium | Controller for Chromium-based browsers. |
| Elinks | Controller for the Elinks text-mode browser. |
| Error | Exception raised when browser operations fail. |
| Galeon | Controller for the Galeon browser (older Linux browser). |
| GenericBrowser | Basic controller for browsers launched via command line. |
| Grail | Controller for the Grail browser (historical Python browser). |
| Konqueror | Controller for the Konqueror browser (KDE browser). |
| MacOSX | Controller for the default browser on macOS. |
| MacOSXOSAScript | Controller using AppleScript to open browsers on macOS. |
| Mozilla | Controller for Mozilla and Firefox browsers. |
| Netscape | Controller for Netscape browser (older browser). |
| Opera | Controller for the Opera browser. |
| UnixBrowser | Controller for command-line browsers on Unix systems. |
| get() | Get a controller for a specific browser by name. |
| open() | Open a URL in the system's default web browser. |
| open_new() | Open a URL in a new browser window if possible. |
| open_new_tab() | Open a URL in a new tab if the browser supports tabs. |
| register() | Register a new browser type so you can use it with get(). |