In Python, webbrowser module provides a high-level interface which allows displaying Web-based documents to users. The webbrowser module can be used to launch a browser in a platform-independent manner as shown below:
Code #1 :
This opens the requested page using the default browser. To have a bit more control over how the page gets opened, use one of the following functions given below in the code –
Code #2 : Open the page in a new browser window.
Code #3 : Open the page in a new browser tab.
These will try to open the page in a new browser window or tab, if possible and supported by the browser. To open a page in a specific browser, use the
webbrowser.get() function to specify a particular browser.
Code #4 :
Being able to easily launch a browser can be a useful operation in many scripts. For example, maybe a script performs some kind of deployment to a server and one would like to have it quickly launch a browser so one can verify that it’s working. Or maybe a program writes data out in the form of HTML pages and just like to fire up a browser to see the result. Either way, the webbrowser module is a simple solution.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- How to draw 2-layered and colored spider web in Python using Turtle Module?
- Delete Google Browser History using Python
- Get Browser History using Python in Ubuntu
- Browser Automation Using Selenium
- Creating a tabbed browser using PyQt5
- Creating a simple browser using PyQt5
- Python | Writing to an excel file using openpyxl module
- Count frequencies of all elements in array in Python using collections module
- Stack and Queue in Python using queue Module
- Testing in Python using doctest module
- Python | ASCII art using pyfiglet module
- Python | Adjusting rows and columns of an excel file using openpyxl module
- Python | Plotting charts in excel sheet using openpyxl module | Set - 1
- Python | Convert Image to Pdf using img2pdf module
- Python | Plotting charts in excel sheet using openpyxl module | Set – 2
- Python | Plotting charts in excel sheet using openpyxl module | Set 3
- Python | Create and write on excel file using xlsxwriter module
- Python | Plotting Area charts in excel sheet using XlsxWriter module
- Python | Plotting bar charts in excel sheet using XlsxWriter module
- Python | Plotting Radar charts in excel sheet using XlsxWriter module
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.