e Learning

Learn How to Open Web Browser in Python Script

In this tutorial we are going to learn how open web browser using python 3.

Python has a module called webbrowser, which allows to open the web browser from a python script By simply calling the open() function of the module.

The webbrowser.open() method will open your default web browser with a given url.


First, we need to import the python webbrowser module using import statement.

import webbrowser

Then called the open() function with the URL of the website as an argument.

import webbrowser


Above Python 3 script will open the url https://google.com with default web browser of the users computer.

Select the Web Browser

Webbrowser module by default use the system default web browser, but combining .open() function with .get() function, we can open a different browser.

Example 1

import webbrowser


As per the above example url https://bing.com will be open with the firefox.

Example 2

import webbrowser


Above python script will open google chrome in Linux.

In Microsoft Windows, you will have to add the executable path of the web browser to windows PATH variable, in order to get() function to work.