Python開啟和關閉網頁

2021-09-27 00:14:15 字數 663 閱讀 6310

#匯入需要用到的模組

import webbrowser

import codecs

import time

import requests

import os

#定義要開啟的網頁

url = ''

#判斷網頁位址是否有效

r = requests.get(url, timeout=5)

result = r.status_code

if (result == 200):

#如果網頁位址有效則開啟網頁

webbrowser.open(url)

print "open success",url

time.sleep(15)

#然後關閉瀏覽器

os.system('taskkill /f /im iexplore.exe')

網頁位址可以隨意定義.

關閉瀏覽器命令,隨著使用瀏覽器的不同而使用不同的命令。

例如,本例使用的是ie瀏覽器,命令為:

os.system('taskkill /f /im iexplore.exe')

如果使用的是chrome瀏覽器,則命令為:

os.system('taskkill /f /im chrome.exe')

python實現指定網頁的開啟和關閉

firefox瀏覽器在使用taskklill命令是需要強制關閉程序,需要帶上 f。coding utf 8 import os,time import webbrowser 定義開啟web函式 defopen web i,j,url m 0while mn 0while nwebbrowser.op...

dos 開啟 關閉網頁

dos 開啟網頁 dos開啟網頁王法 命令列開啟網頁 執行輸入 explorer dos命令開啟網頁 iexplore ie 程序開啟 比如你在破永珍時 乾掉了主程序!ntsd c q p pid 那這個可以幫你!explorer dos開啟網頁 netsh inte ce ip set addre...

開啟和關閉Oracle Flashback

1 開啟flashback 關閉資料庫 sql shutdown immediate 啟動到mount方式 sql startup mount 如果歸檔沒有開啟,開啟歸檔 因為flashback依賴media recovery,所以在開啟flashback之前必須先啟用歸檔 sql alter da...