为pythonselenium定义一个无限循环,目前需要改进

2024-10-01 17:25:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我的脚本充当一个web浏览器,它根据上提供的网站浏览网络链接.txt以及规定的时间间隔。它应该全天候提供。有人看到任何可能的方法来根据脚本的目标改进代码吗?代码如下:

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

Tags: pathkey代码fromimporttxt脚本time
1条回答
网友
1楼 · 发布于 2024-10-01 17:25:28

即使代码正在运行,计算机也有可能被锁定,因为它不会将程序的操作识别为个人操作。你需要做的就是改变你的电脑配置,这样它就不会在15分钟内锁定

我有这样的想法,我让我的mac在5分钟后关闭,即使我的selenium打开浏览器,做很多动作,它也会锁定屏幕。它不需要有任何问题,只是没有重置储物柜计时器,因为你的程序只是另一个进程在运行。在

如果你还有什么要问的,thisthis的帖子一定能帮到你。在

相关问题 更多 >

    热门问题