How to open a webpage in python

(*-*)浩
Release: 2019-07-09 10:11:38
Original
10573 people have browsed it

Method one for opening a web page in Python:

How to open a webpage 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')
Copy after login

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)
Copy after login

webbrowser.open() method:

webbrowser.open(url, new=0, autoraise=True)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template