Webbrowser Module

Download python eBook

Introduction

According to Python's standard documentation, the webbrowser module provides a high-level interface to allow displaying Web-based documents to users. This topic explains and demonstrates proper usage of the webbrowser module.

Syntax

  • webbrowser.open(url, new=0, autoraise=False)
  • webbrowser.open_new(url)
  • webbrowser.open_new_tab(url)
  • webbrowser.get(usage=None)
  • webbrowser.register(name, constructor, instance=None)

Parameters

ParameterDetails
webbrowser.open() 
urlthe URL to open in the web browser
new0 opens the URL in the existing tab, 1 opens in a new window, 2 opens in new tab
autoraiseif set to True, the window will be moved on top of the other windows
webbrowser.open_new() 
urlthe URL to open in the web browser
webbrowser.open_new_tab() 
urlthe URL to open in the web browser
webbrowser.get() 
usingthe browser to use
webbrowser.register() 
urlbrowser name
constructorpath to the executable browser (help)
instanceAn instance of a web browser returned from the webbrowser.get() method

Remarks

The following table lists predefined browser types. The left column are names that can be passed into the webbrowser.get() method and the right column lists the class names for each browser type.

Type NameClass Name
'mozilla'Mozilla('mozilla')
'firefox'Mozilla('mozilla')
'netscape'Mozilla('netscape')
'galeon'Galeon('galeon')
'epiphany'Galeon('epiphany')
'skipstone'BackgroundBrowser('skipstone')
'kfmclient'Konqueror()
'konqueror'Konqueror()
'kfm'Konqueror()
'mosaic'BackgroundBrowser('mosaic')
'opera'Opera()
'grail'Grail()
'links'GenericBrowser('links')
'elinks'Elinks('elinks')
'lynx'GenericBrowser('lynx')
'w3m'GenericBrowser('w3m')
'windows-default'WindowsDefault
'macosx'MacOSX('default')
'safari'MacOSX('safari')
'google-chrome'Chrome('google-chrome')
'chrome'Chrome('chrome')
'chromium'Chromium('chromium')
'chromium-browser'Chromium('chromium-browser')

Related Examples

Stats

364 Contributors: 1
Friday, December 30, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook