python2.7 開啟ie瀏覽器並開啟指定網頁
阿新 • • 發佈:2019-02-20
# -*- coding: utf-8 -*-
import webbrowser,os,time
base_path = 'F:\webapps' #重啟日誌資訊檔案的路徑
log_file = base_path + '\%s.log' %(time.strftime('%Y%m%d',time.localtime()))
now = int(time.time())
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
def chongqi():
try:
detection = len(os.popen('tasklist /FI "IMAGENAME eq iexplore.exe"').read().decode('cp936'))
if detection > 19: #檢測ie程序是否存在,存在則殺掉,不存在則直接開啟html檔案
os.system('taskkill /F /IM iexplore.exe') #把ie瀏覽器殺掉
webbrowser.open_new('F:\\webapps\\haha\\iexplore1.lnk')
webbrowser.open_new('F:\\webapps\\haha\\iexplore2.lnk') #重啟每個html檔案,這裡將html檔案都做成快捷方式更方便
webbrowser.open_new('F:\\webapps\\haha\\iexplore3.lnk')
webbrowser.open_new('F:\\webapps\\haha\\iexplore4.lnk')
os.system("echo %s browser restart,url open succesfully! >> %s" %(otherStyleTime, log_file))
else:
webbrowser.open_new('C:\inetpub\wwwroot\iexplore1.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore2.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore3.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore4.lnk')
os.system("echo %s browser do not restart,url open successfully! >> %s" %(otherStyleTime, log_file))
except:
os.system("echo %s restart url failed! >> %s" %(otherStyleTime, log_file))
if __name__ == '__main__':
chongqi()
import webbrowser,os,time
base_path = 'F:\webapps' #重啟日誌資訊檔案的路徑
log_file = base_path + '\%s.log' %(time.strftime('%Y%m%d',time.localtime()))
now = int(time.time())
timeArray = time.localtime(now)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
def chongqi():
try:
detection = len(os.popen('tasklist /FI "IMAGENAME eq iexplore.exe"').read().decode('cp936'))
if detection > 19: #檢測ie程序是否存在,存在則殺掉,不存在則直接開啟html檔案
os.system('taskkill /F /IM iexplore.exe') #把ie瀏覽器殺掉
webbrowser.open_new('F:\\webapps\\haha\\iexplore1.lnk')
webbrowser.open_new('F:\\webapps\\haha\\iexplore2.lnk') #重啟每個html檔案,這裡將html檔案都做成快捷方式更方便
webbrowser.open_new('F:\\webapps\\haha\\iexplore3.lnk')
webbrowser.open_new('F:\\webapps\\haha\\iexplore4.lnk')
os.system("echo %s browser restart,url open succesfully! >> %s" %(otherStyleTime, log_file))
else:
webbrowser.open_new('C:\inetpub\wwwroot\iexplore1.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore2.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore3.lnk')
webbrowser.open_new('C:\inetpub\wwwroot\iexplore4.lnk')
os.system("echo %s browser do not restart,url open successfully! >> %s" %(otherStyleTime, log_file))
except:
os.system("echo %s restart url failed! >> %s" %(otherStyleTime, log_file))
if __name__ == '__main__':
chongqi()