Python webbrowser Introduction














































Python webbrowser Introduction



 Description
 This Python Module provides a high-level interface which allows users to display web-based Documents. 
 In most of the cases user need to call only one function named open() function from webbrowser module to   get his task completed.
 We can use the script webbrowser  as Command-Line Interface by giving URL as an argument. 

 Installation:
 It is a pre-built library so no need to install it externally.

 Exceptions defined in this Module :
 Exception Name : webbrowser.Error
 Description : Exception raised when browser control error occured.

 Functions defined in this Module:

 Function Name : webbrowser.open(url, new=0, autocruise=True)
 Description : Display URL using the default browser. If new is 0, the URL is opened in the same browser   window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser   page (%u201Ctab%u201D) is opened if possible. If autocruise is True, the window is raised if possible (note that under   many window managers this will occur regardless of the setting of this variable).
 
 Function Name : webbrowser.open_new(url)
 Description : Open URL in a new window of the default browser, if possible, otherwise, open URL in the   only browser window.
 
 Function Name : webbrowser.open_new_tab(url)
 Description : Open URL in a new page (%u201Ctab%u201D) of the default browser, if possible, otherwise equivalent to   open_new().

 Function Name : webbrowser.get(using=None)
 Description : Return a controller object for the browser type using. If using is None, return a controller for a   default browser appropriate to the caller%u2019s environment.
 
 Function Name : webbrowser.register(name, constructor, instance=None, *, preferred=False)
 Description : Register the browser type name. Once a browser type is registered, the get() function can   return a controller for that browser type. If instance is not provided, or is None, constructor will be called   without parameters to create an instance when needed. If instance is provided, constructor will never be   called, and may be None.

 Sample Code : 
 import webbrowser
 webbrowser.open('https://www.cppsecrets.com')

 Output : 
 It will open "www.cppsecrets.com" in default browser successfully.
 
 
 

                                                                                                                                                             NEXT-->

Comments