Example of using Python to invoke a browser and open a URL _python

Source: Internet
Author: User

Python opens the browser, you can do a simple brush the Web applet. Only for study, not for illegal use.

Python's WebBrowser module supports some of the following three ways to do the browser:

Copy Code code as follows:

Webbrowser.open (URL, new=0, autoraise=true)
Webbrowser.open_new (URL)
Webbrowser.open_new_tab (URL)

We need to know the Webbrowser.open () method:

Copy Code code as follows:
Webbrowser.open (URL, new=0, autoraise=true)

Access the URL address in the system's default browser, if New=0,url will be in the same
browser window; If new=1, a new browser window will open; new=2
The new browser tab will be opened.

The Webbrowser.get () method can get the action object to the System browser.

The Webbrowser.register () method registers the browser type, and the type name that is allowed to be registered is as follows:

Copy Code code as follows:
Type name Class name Notes
' Mozilla ' Mozilla (' Mozilla ')
Firefox mozilla (' Mozilla ')
' Netscape ' Mozilla (' Netscape ')
' Galeon ' Galeon (' Galeon ')
' Epiphany ' Galeon (' epiphany ')
' Skipstone ' backgroundbrowser (' Skipstone ')
' Kfmclient ' Konqueror (1)
' Konqueror ' Konqueror (1)
' KFM ' Konqueror (1)
' Mosaic ' backgroundbrowser (' mosaic ')
' Opera ' opera ()
' Grail ' Grail ()
' Links ' genericbrowser (' links ')
' ELinks ' elinks (' elinks ')
' Lynx ' genericbrowser (' Lynx ')
' w3m ' genericbrowser (' w3m ')
' Windows-default ' Windowsdefault (2)
' MacOSX ' macosx (' Default ') (3)
' Safari ' MacOSX (' Safari ') (3)
' Google-chrome ' Chrome (' google-chrome ')
' Chrome ' chrome (' chrome ')
' Chromium ' chromium (' chromium ')
' Chromium-browser ' chromium (' chromium-browser ')

DEMO:
Copy Code code as follows:

#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import Sys
Import WebBrowser
Sys.path.append ("Libs")



url = ' http://www.baidu.com '
Webbrowser.open (URL)
Print Webbrowser.get ()

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.