Method one for opening a web page in Python:
By referencing the os package, call the system method and call the system's ie program to open the URL ( Recommended learning: Python video tutorial)
The code is as follows:
import os #C:/Program Files/Internet Explorer/iexplore.exe为浏览器所在路径 os.system('"C:/Program Files/Internet Explorer/iexplore.exe" http://www.baidu.com')
python Method 2 of opening a web page:
Through the open method of webrowser Open:
Python's webbrowser module supports some operations on the browser. There are mainly three methods:
1.webbrowser.open(url, new=0, autoraise=True) 2.webbrowser.open_new(url) 3.webbrowser.open_new_tab(url)
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 port will be opened;
new=2 A new browser tab will be opened.
webbrowser.get() method:
You can get the operation object of the system browser.
webbrowser.register() method:
You can register the browser type and allow the registered type name.
For more Python related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to open a webpage in python. For more information, please follow other related articles on the PHP Chinese website!