Launching webbrowser

In this section, we will learn about the webbrowser module of Python. This module has functions to open URLs in browser applications. We will see a simple example. Create a script called open_web.py and write the following code in it:

import webbrowser
webbrowser.open('https://timesofindia.indiatimes.com/world')

Run the script as follows:

$ python3 open_web.py

Output:
Url mentioned in open() will be opened in your browser.

webbrowser – Command line interface

You can also use the webbrowser module of Python through the command line and can use all of it. To use webbrowser through the command line, run the following command:

$ python3 -m webbrowser -n https://www.google.com/

Here, https://www.google.com/ will be opened in the browser window. You can use the following two options:

  • -n: Open a new window
  • -t: Open a new tab
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset