This content was deleted by the author. You can see it from Blockchain History logs.

Python Tips 5 - Webbrowser package

Python Tips - Webbrowser package


Python is often used as an automation tool. Today, we take a look at the webbrowser package.

Python est souvent utilisé comme outil d'automatisation. Aujourd'hui, nous nous penchons sur le paquet webbrowser.

This module is quite simple to use. That makes it very cool to work with to setup an automation script rapidly.

Ce module est très simple à utiliser. Il est donc très agréable de travailler avec lui pour mettre en place rapidement un script d'automatisation.


You can import it with:

import webbrowser

Simply open an url:

# pass the url as a string
webbrowser.open(url)

Open a url in a new tab:

# pass the url as a string
webbrowser.open_new_tab(url)

Open a url in a new window:

# pass the url as a string
webbrowser.open_new(url)

By using the package this way, you will open the URLs in your default browser. If you wish to use another browser, you will have to use the controller object.

The list of browsers supported natively can be found here.

If it's not there, you can use the webbrowser.register() function to register it before using the associated controller.


To get the controller, it's quite simple

# pass the url as a string
firefox = webbrowser.get(using="firefox")

Then you can use it just like before.

# pass the url as a string
firefox.open(url)

# pass the url as a string
firefox.open_new_tab(url)

# pass the url as a string
firefox.open_new(url)

You made it to the end, bravo! If you have any questions, don't forget to ask. See you next time!

You will be able to find a good part of the articles in this account in this repository.

To go directly to the section you are currently viewing click here.

Latest article in the series: Python Tips 4 - Playing with recursion