How to open Webpage using Python

From Python, a call can be sent to some web browser for opening a Url. For doing this you can use webbrowser python module. Let’s first see what’s Webbrowser Python Module and What functions does it contain?

Web Browser Python Module Functions

Below is a table containing Web Browser module’s functions with descriptions for each one.

Web Browser Module FunctionDescription, new, autoraise=True)Open url using default browser
webbrowser.open_new(url)Open url in a new window of default browser
webbrowser.open_new_tab(url)Open url in new tab of default browser

Opening Webpage using Python’s Function

Syntax of Function :
Parameters : url, new, autoraise

Value of parameter new will decide whether to open new window or browser tab for opening the url.
• new = 0 means url will be opened in same browser window
• new = 1 means url will be opened in new browser window
• new = 2 means url will be opened in new Tab, if browser is already opened

Value of parameter autoraise if sets to True will make Python to raise up new window for url.

import webbrowser'', new=0, autoraise=True)
import webbrowser'', new=1, autoraise=True)
import webbrowser'', new=2, autoraise=True)

Opening Webpage using Python’s webbrowser.open_new() Function

Syntax of Function : webbrowser.open_new(parameter)
Parameters : url

This function webbrowser.open_new(url) opens a new window of default browser and opens url in it.

import webbrowser


Opening Webpage using Python’s webbrowser.open_new_tab() Function

Syntax of Function : webbrowser.open_new_tab(parameter)
Parameter : url

This function webbrowser.open_new_tab(parameter) opens a new tab of default browser and then opens url in it.

import webbrowser


Leave a Comment