How to open the URL in browsers using Python?

The easy way to develop the application in python is that we can easily import the libraries. Among those, webbrowser module provides a high-level interface to allow displaying Web-based documents to users.

1. Download and install webbrowser library

$ pip install webbrowser

2. Open a page in the browser

import webbrowser
webbrowser.open('https://www.google.com')

3. Open a page with new tab in the browser

import webbrowser
webbrowser.open_new('https://www.google.com')

4. Open a page in the specific browser

import webbrowser
chrome= "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
webbrowser.get(chrome).open("https://www.google.com")

That’s it. I hope this will help. 🙂
Photo: https://www.brandeps.com

Leave a Reply

Your email address will not be published. Required fields are marked *