Python打開網(wǎng)頁的幾種方式
方法1:直接調(diào)用系統(tǒng)命令 os
#導入包
import os
#執(zhí)行包命令
os.system('"C:/Users/Public/AppData/Local/Google/Chrome/Application/chrome.exe" https://www.baidu.com')
方法2:引用webrowser包文章來源:http://www.zghlxwxcb.cn/news/detail-576834.html
#導入包
import webbrowser
#定義訪問路徑
url = "https://www.baidu.com"
##執(zhí)行包命令打開指定網(wǎng)頁
webbrowser.open(url, new=0, autoraise=True)
方法3:引用selenium工具,解決閃退問題
附:Pycharm 安裝selenium 工具說明文章來源地址http://www.zghlxwxcb.cn/news/detail-576834.html
#導入包
from selenium import webdriver
#導入時間模塊,可用于控制打開網(wǎng)頁的瀏覽時長,解決閃退問題
import time
OpenURL = webdriver.Chrome()
#定義訪問路徑
URL = "https://www.baidu.com"
OpenURL.get(URL) # 打開百度瀏覽器
time.sleep(5) #延遲5秒
OpenURL.quit() #關(guān)閉
到了這里,關(guān)于Python 打開網(wǎng)頁的幾種方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!