Back
Featured image of post Open Browser in Python

Open Browser in Python

We can use webbrowser module to open browser in Python.

Command line´╝Ü

python -m webbrowser -t "<URL>"

.py script:

url = '<URL>'

# Open straightly (default)
webbrowser.open(url)

# Open in new tab
webbrowser.open_new_tab(url)

# Open in new window
webbrowser.open_new(url)

# Assign a browser´╝łopen_newŃÇüopen_new_tab support this way too´╝ë
webbrowser.get('<Browser Code>').open(url)

The browser codes is among mozilla firefox ´╝łMozilla Firefox´╝ë opera (Opera) windows-default (Windows default browser´╝ë macosx ´╝łMac OS default browser´╝ë safari ´╝łSafari´╝ëgoogle-chrome chrome ´╝łChrome´╝ë chromium chromium-browser ´╝łChromium and other browsers based on chromium´╝ë

References´╝Ü

  1. https://docs.python.org/3.7/library/webbrowser.html
Built with Hugo
Theme Stack designed by Jimmy