Home >Backend Development >Python Tutorial >Python calls the browser to implement the web page brushing applet
Python opens the browser and can make simple small programs for browsing web pages and other imaginative programs. But it is for learning only, please do not use it for illegal purposes.
Python's webbrowser module supports some operations on the browser
There are mainly the following three methods:
webbrowser.open(url, new=0, autoraise=True) webbrowser.open_new(url) webbrowser.open_new_tab(url)
Any of the above three methods can be tested under python2.7, but this requires Test under windows
We need to understand the webbrowser.open() method:
webbrowser.open(url, new=0, autoraise=True)
Access the url address in the system's default browser, if new=0 , the url will be opened in the same
browser window; if new=1, a new browser window will be opened; new=2
a new browser tab will be opened.
The webbrowser.get() method can obtain the operation object of the system browser. The
webbrowser.register() method can register browser types, and the type names allowed to be registered are 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')
Example:
#!/usr/bin/env python #-*- coding:UTF-8 -*- import webbrowser url = 'http://www.pythontab.com' webbrowser.open(url) print webbrowser.get()