Open Chrome with Python and webbrowser

python open a link in chrome

Open a web page directly with Python

python open a link in chrome
python opens a link in chrome

In case you need to open a web page using Python in “Chrome”, you can use this code:

You have to change the path of Chrome (or any other browser you want) checking where it has been installed into your computer’s folders .

Example: use webbrowser to go into your admin page of word press

Use it as a bookmark

You could use this code to get access to your admin pages adding the link, simply like this

Get the code into a function to use it more abstractly

You the could think to make a nice function

Use different browsers

and, for future additional features in your code, you could also think to specify the browser, why not?

Open more pages at once with webbroser

When we open the browser, usually there are some sites we check first. For example, if you have some blogs, like me, you will want to check them to see statistics, add post and so on. Having said this, the next idea that comes to my mind is to open more pages, this could be a nice shortcut to justify using python to make this. I could do it going to the settings of chrome, but I like automation and I am more at my ease with python instead of going into chrome settings… and obviously is more flexible and… even fun.

Add a tkinter window to show you the sites opened

You could, then, add a window that pops up showing you the sites opened with the script.

If you want to make things fast, save (as, for example) this file in the default folder of windows (the folder that windows open in the search bar on the bottom left of the desktop)

You can open your sites writing the name of the python file

and from the search bar digit, hit enter and you will have chrome opened with the sites in that list.

Here is the pop up window popping out

Sort of pop up window made with tkinter

To be continued…

Last thing we could add to this code is the chance to choose wich site to open among a list with checkboxes.

Let’s see how you can make checkboxes in tkinter:


Adapting the code to our program

Let’s add the sites to the checkbuttons above

The program prints at console 1 or zero when you check or uncheck the buttons

This is just an example, a possible use of the checkbuttons in tkinter. Come back here to see if I added some new stuffs to this project to amplify its features.

Now lets copy the openweb function in this script

We need to add a button that will check the checkbuttons selected

The final script

Ok, now we made it. We can check the sites that we want to open checking the checkbuttons in the windows that pop ups. I added a link of this post so that I could find it easily while I was editing it without going through the word press web editor, menus and searches.

Here is the window:

The code

If you come back here I will probably do a live coding of this script… soon.

For italians…

Aprire una pagina web con Chrome usando Python e webbrowser

Se avete bisogno di aprire un link in Chrome usando Python, potete farlo in vari modi. È possibile, ad esempio, farlo con il modulo webbrowser.

Per prima cosa importate il modulo, poi con le funzioni get (per trovare il percorso del programma Chrome nel vostro pc) e open (per aprire il link), otterrete il risultato voluto.