Opening The Web Browser in Python (webbrowser Module)


Openning web browser is particularly useful if you are building an automation script that does a bunch of tasks and at the end you want to open browser window to perform some other task.

For example, you are building a website and a python program that automates the task of deploying your website and opens website in browser after deployment is successful.

In this tutorial we are going to learn how to open web browser in python with example.

To open web browser with python programming language, we use python module called webbrowser. This module has method open() to open a given link and it takes web url as an argument.

Following python program prints "Deployment is Completed." and it opens "https://www.codesansar.com".

webbrowser Module Example


import webbrowser

print('Deployement is Completed.')
webbrowser.open('https://www.codesansar.com')

Output

Deployement is Completed.
# And website https://www.codesansar.com 
# will open in your default browser.

We encourage you to run above python program in your system to understand it more clearly.