Python Module Introduction-webbrowser: A convenient web browser controller

Source: Internet
Author: User


Source: lib/webbrowser.py

Brief introduction

The WebBrowser module provides a high-level interface for displaying Web-based documents. In most cases, simply call the open () function.

Under Unix X11, it is preferred to call the graphics browser. If the graphics browser is unavailable or does not display a terminal, a text-mode browser is used. If you use a text-mode browser, the calling process will block until the user exits the browser.

If the browser environment variable is set, it overrides the default browser list for the platform. Browser is a list of browsers that are os.pathsep segmented. If a partial value of the list contains the string "%s", the argument to the browser command line is resolved.

When using a remote browser for a non-UNIX platform or UNIX, the control process does not wait for the user to complete the browse, but allows the remote browser to display its own window. If there is no remote browser, the control process will launch a new browser and wait.

The WebBrowser supports the command line interface. It accepts the URL as a parameter. Optional parameter: "-n" opens the URL in a new browser window; "-T" opens a new tab.

$ python-m webbrowser-t "Http://automationtesting.sinaapp.com/blog/url" [Email protected]:~$ [4860:4860:0520/095513: ERROR:url_pattern_set.cc] Invalid URL pattern:chrome://print/*[4897:4897:0520/095513:error:sandbox_linux.cc ( 343)] Initializesandbox () called with multiple threads in process gpu-process[email protected]:~$ [email protected]:~$ PYT Hon-m webbrowser-t "Http://automationtesting.sinaapp.com/blog/url" [email protected]:~$ has created a new window in an existing browser session. [Email protected]:~$
Quick Start
Import webbrowserwebbrowser.open (' http://automationtesting.sinaapp.com ') webbrowser.open_new_tab (' HTTP// Automationtesting.sinaapp.com/blog/url ')
The previous meeting opens two tabs.Interface Introduction
    • Exception: Exception webbrowser. Error: This exception is thrown when the browser controls an error.

Function
    • Webbrowser.open (URL, new=0, autoraise=true)

Use the default browser to access the URL. If new equals 0, the URL is opened as far as possible in an existing browser window. If new is equal to 1, it opens a newer browser window. New equals 2, as far as possible, open the label (tab) in the browser. If Autoraise is true, the browser window appears first (note that in most window managers).

Note on some platforms, the system's associated program may be started when the file name is opened. Other systems default to the most resource-efficient way to open the browser.

    • Webbrowser.open_new (URL)

Use the default browser to open the URL, try to have only one window

    • Webbrowser.open_new_tab (URL)

Use the default browser to open the URL in the new tab.

    • Webbrowser.get ([name])

Returns the development of a browser controller object. If name is empty, the controller of the default browser is returned.

    • Webbrowser.register (name, constructor, Instance=none)

Registered Browser type: name. The Get () function can return a controller of that browser type after registration. If instance is not provided or none, the constructor can call without arguments and create an instance. If a instance is provided, the constructor is not called.

This entry a-useful if you plan to either set the BROWSER variable or call get () with a nonempty argument MATC Hing the name of a handler you declare.

Valid only if you set the browser variable or call get () with a non-null argument. You declare the name of a handler to match.

Pre-defined browser types

See also: https://docs.python.org/2/library/webbrowser.html

Browser Controller objects
    • Controller.open (URL, new=0, autoraise=true)

    • Controller.open_new (URL)

    • Controller.open_new_tab (URL)

Please refer to the Module function documentation.


Resources
    • WebBrowser English documents

    • Author Blog: http://my.oschina.net/u/1433482


Python Module Introduction-webbrowser: A convenient web browser controller

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.