我的腳本充當一個瀏覽網頁的瀏覽器,它根據links.txt上提供的網站和所述的時間間隔進行瀏覽。它應該全天候提供。根據腳本的目標,有沒有人看到任何可能的方法來改進代碼?以下是代碼:爲Python Selenium定義一個無限循環,目前需要改進
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pyautogui
import time
import os.path as path
import sys
def runlinks(f):
for line in f:
key, val = line.split(";")
driver.get(key)
pyautogui.moveTo(5000, None)
time.sleep(int(val))
pyautogui.press('f15')
return()
driver = webdriver.Firefox()
pyautogui.press('f11')
count = 0
infile = "Z:\Full-Route\links.txt" #This is your links's file Path
while count < 1:
try:
with open(infile, "r") as f:
runlinks(f)
except:
pass
現在的代碼有什麼問題?你想要改進什麼? – Andersson