Welcome folks today in this blog post we will be using the webbrowser
library in python to automate chrome
browser and open url in it. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the below library using the below pip
command as shown below
pip install webbrowser
And now you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 |
import webbrowser # Open the Chrome browser chrome = webbrowser.get('chrome') chrome.open_new_tab('https://www.google.com') |
This script first imports the webbrowser
library and then uses the get()
function to specify that we want to use the Chrome browser. It then uses the open_new_tab()
function to open a new tab in Chrome and navigate to the specified URL (in this case, Google.com).
Alternatively, you can also use the open()
function instead of open_new_tab()
to open the URL in the default browser.
1 |
webbrowser.open('https://www.google.com') |