1、python 打開瀏覽器的方法: 1. startfile方法(打開指定瀏覽器) 1 2 import os os.startfile("C:\Program Files\internet explorer\iexplore.exe") 2. system方法 打開指定瀏覽器: 1 2 import os os.system('"C:\Program Files\internet explorer\iexplore.exe"') 經過指定瀏覽器打開指定的網址: 1 2 import os os.system('"C:\Program Files\internet explorer\iexplore.exe" http://www.baidu.com') 3. 更好地解決方案WEBBROWER 經過默認瀏覽器打開: 1 2 import webbrowser webbrowser.open("http://www.baidu.com") 經過指定瀏覽器打開指定的網址: 1 2 3 4 5 6 import webbrowser IEPath = "C:\Program Files\internet explorer\iexplore.exe" webbrowser.register('IE', None, webbrowser.BackgroundBrowser(IEPath)) webbrowser.get('IE').open('http://www.baidu.com', new=1,autoraise=True) # 或者 webbrowser.open_new_tab('http://www.baidu.com') 參考:python_隨機調用一個瀏覽器打開網頁 參考:python打開瀏覽器的三種方法 參考:webbrowser模塊使用—用chrome打開頁面 參考:python---webbrowser模塊的使用,用非系統默認瀏覽器打開 參考:python爬蟲(20)使用真實瀏覽器打開網頁的兩種方法 2、python 打開文件的方法: 1. startfile方法 1 2 3 >>> import os >>> os.startfile(r"D:\MODISPRO\操做指南.txt") >>> os.startfile(r"D:\MODISPRO\操做指南.docx") 2. system方法 1 2 3 >>> import os >>> os.system(r"D:\MODISPRO\操做指南.txt") >>> os.system(r"D:\MODISPRO\操做指南.docx")
webbrowser模塊相信你們都很熟悉經常使用的方法有: webbrowser.open(url, new=0, autoraise=True) webbrowser.open(url, new=0, autoraise=True)webbrowser.open_new(url) webbrowser.open_new_tab(url) webbrowser.get()方法能夠獲取到系統瀏覽器的操做對象。 webbrowser.register()方法能夠註冊瀏覽器類型,而容許被註冊的類型能夠參閱:http://www.cnblogs.com/hongten/p/hongten_python_webbrowser.html所列出的內容。 首先我仍是講一下網上看的比較多的打開瀏覽器的方法 import webbrowser webbrowser.open('www.baidu.com') 這樣就能夠打開一個百度頁面,可是很惱火的狀況是,默認使用IE打開的,至少個人電腦是默認IE打開的。 下面就講一下用別的瀏覽器打開的方法: --------------------- 做者:嚯嚯嘻嘻哈 來源:CSDN 原文:https://blog.csdn.net/iobed/article/details/17186773 版權聲明:本文爲博主原創文章,轉載請附上博文連接!
from webbrowser import Chrome webbrowser.register('chrome', Chrome('chrome'))
詳情:html
https://docs.python.org/2/library/webbrowser.htmlpython