create account

Python Tips 5 - Webbrowser package by slashformotion

View this thread on: hive.blogpeakd.comecency.com
· @slashformotion · (edited)
$1.04
Python Tips 5 - Webbrowser package
# Python Tips - Webbrowser package


![](https://www.oneclicksolutions.com.au/wp-content/uploads/2011/07/browsericons-539x205.png)

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:
```Python
import webbrowser
```

Simply open an url:

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

Open a url in a new tab:
```Python
# pass the url as a string
webbrowser.open_new_tab(url)
```

Open a url in a new window:
```Python
# 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](https://docs.python.org/3.8/library/webbrowser.html#webbrowser.register).

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

```Python
# pass the url as a string
firefox = webbrowser.get(using="firefox")
```
Then you can use it just like before.

```Python
# 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)
```


![](https://images.hive.blog/0x0/https://images.hive.blog/DQmSkA2zZKCkkqxJKiG1srWbDzi4V74KMnRmg7LfbQDka6z/dividers-06.png)

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

![](https://images.hive.blog/0x0/https://images.hive.blog/DQmSkA2zZKCkkqxJKiG1srWbDzi4V74KMnRmg7LfbQDka6z/dividers-06.png)
---
You will be able to find a good part of the articles in this account [in this repository](https://github.com/slashformotion/hive-base).

To go directly to the section you are currently viewing [click here](https://github.com/slashformotion/hive-base/tree/master/content/series/PythonTips/PythonTips_n5-WebbrowserPackage).

[Latest article in the series: ***Python Tips 4 - Playing with recursion***
](https://peakd.com/hive-163521/@slashformotion/python-tips-4-playing-with-recursion)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorslashformotion
permlinkpython-tips-5-webbrowser-package
categoryhive-163521
json_metadata{"app":"peakd/2020.07.1","format":"markdown","tags":["python","fr","dev","webbrowser"],"users":["slashformotion"],"links":["https://docs.python.org/3.8/library/webbrowser.html#webbrowser.register","https://github.com/slashformotion/hive-base","https://github.com/slashformotion/hive-base/tree/master/content/series/PythonTips/PythonTips_n5-WebbrowserPackage","/hive-163521/@slashformotion/python-tips-4-playing-with-recursion"],"image":["https://www.oneclicksolutions.com.au/wp-content/uploads/2011/07/browsericons-539x205.png","https://images.hive.blog/DQmSkA2zZKCkkqxJKiG1srWbDzi4V74KMnRmg7LfbQDka6z/dividers-06.png"]}
created2020-07-07 12:50:03
last_update2020-07-07 14:26:51
depth0
children4
last_payout2020-07-14 12:50:03
cashout_time1969-12-31 23:59:59
total_payout_value0.522 HBD
curator_payout_value0.516 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,538
author_reputation2,410,764,686,560
root_title"Python Tips 5 - Webbrowser package"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,389,351
net_rshares3,508,964,909,561
author_curate_reward""
vote details (49)
@cleanplanet ·
CleanPlanet Upvote
Thanks to @theophile.roos for burning [800 PLANET](https://hive-engine.com/?p=market&t=PLANET)! You have been rewarded with a 80% vote. Your action makes this project grow and helps to restore a Clean Planet! Join us on our [Discord Channel](https://discord.gg/FkVTpwU) and on [our website](https://cleanplanet.io)
properties (22)
authorcleanplanet
permlinkjr5o3o647acqewa67sidxj
categoryhive-163521
json_metadata{"app":"CleanPlanet_Bot/0.1"}
created2020-07-07 16:47:51
last_update2020-07-07 16:47:51
depth1
children0
last_payout2020-07-14 16:47:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length314
author_reputation85,786,252,576,268
root_title"Python Tips 5 - Webbrowser package"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,392,752
net_rshares0
@gitplait-mod1 ·
Thanks for sharing a nice tutorial.I like the way you share repository with user. We are looking for people like you in our community.

<sub> Your post has been submitted to be curated with @gitplait community account because this is the kind of publications we like to see in our community. </sub>

Join our [Community on Hive](https://hive.blog)
properties (22)
authorgitplait-mod1
permlinkqd3qlf
categoryhive-163521
json_metadata{"users":["gitplait"],"links":["https://hive.blog"],"app":"hiveblog/0.1"}
created2020-07-07 13:53:51
last_update2020-07-07 13:53:51
depth1
children0
last_payout2020-07-14 13:53:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length347
author_reputation64,455,719,431
root_title"Python Tips 5 - Webbrowser package"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,390,183
net_rshares0
@oniemaniego ·
I use this after generating HTML reports, then opens it to the default browser. One thing I observed was when the local filepath is incorrect, it would open Microsoft Edge instead 🤔
properties (22)
authoroniemaniego
permlinkre-slashformotion-qd5lu1
categoryhive-163521
json_metadata{"tags":["hive-163521"],"app":"peakd/2020.07.1"}
created2020-07-08 14:06:00
last_update2020-07-08 14:06:00
depth1
children1
last_payout2020-07-15 14:06:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length181
author_reputation79,934,267,673,603
root_title"Python Tips 5 - Webbrowser package"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,408,355
net_rshares0
@theophile.roos ·
Linux is always the solving element 
properties (22)
authortheophile.roos
permlinkre-oniemaniego-202078t181529762z
categoryhive-163521
json_metadata{"tags":["esteem"],"app":"esteem/2.2.5-mobile","format":"markdown+html","community":"hive-125125"}
created2020-07-08 16:15:30
last_update2020-07-08 16:15:30
depth2
children0
last_payout2020-07-15 16:15:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length36
author_reputation2,082,796,838,634
root_title"Python Tips 5 - Webbrowser package"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,410,163
net_rshares0