There are many things Python can do, and the editor is also working hard to explore. Today I will share with you how to use Python to control the operation and operation of the browser!
Well, there are roughly two ways about this, let me list them one by one:
1. use the system's own library os
With this method, any browser can be used, but you can’t open the web pages one by one, right?
2. use the python integrated library webbroswer
With the support of the webbrowser module, the browser can be controlled and operated. There are roughly three methods:
It seems that although there are three methods, there is still one in essence. The only difference lies in the different parameters passed. webbrowser.open(url, new=0, autoraise=True)
Visit the url address in the default browser of the system, 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 the new browser tab will be The other two functions webbrowser.open_new(url) and webbrowser.open_new_tab(url) are actually opened to return webbrowser.open() This method is just that they have no other two parameters.
You need to register in advance when calling other browsers, otherwise the default browser will open the page.
The browser types supported by the webbrowser library lock are as follows:
These contents can be seen in the source file, the path is: python2.7/libs/webbroser.py