Opening The Web Browser Using Python

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

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 after deployment is successful.

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".

Python Program to Open Web Browser


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.