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 ()