Home >Backend Development >Python Tutorial >Python calls the browser to implement the web page brushing applet

Python calls the browser to implement the web page brushing applet

大家讲道理
大家讲道理Original
2016-11-07 17:12:571511browse

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 must be done under windows Let’s test it

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, url Will open 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 that are 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()

It’s very simple, you can study the deeper uses yourself, click here

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn