我正在使用以下脚本在网站上自动执行任务
如何才能使此脚本每隔60分钟运行一次?
我正在为我的任务使用此代码,它在我手动运行此代码时有效,但我想运行此脚本一次,然后每隔60分钟自动重复一次
下面是我使用的代码
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "/usr/bin/chromedriver"
driver = webdriver.Chrome(PATH)
driver.get("https://freebitco.in")
driver.maximize_window()
time.sleep(2)
driver.find_element_by_link_text('LOGIN').click()
time.sleep(3)
driver.find_element_by_id("login_form_btc_address").send_keys("EMAILADDRESS")
driver.find_element_by_id("login_form_password").send_keys("PASSWORD")
driver.find_element_by_id("login_button").click()
time.sleep(4)
driver.find_element_by_class_name("pushpad_deny_button").click()
time.sleep(3)
driver.find_element_by_id("free_play_form_button").click()
time.sleep(5)
driver.find_element_by_class_name("close-reveal-modal").click()
driver.quit()我想每隔60分钟重复一次这个脚本
发布于 2020-05-02 01:11:48
在代码内部,您可以通过长时间休眠来实现这一点:
while True:
# existing code goes here...
time.sleep(60 * 60) # secs x mins如果在某些情况下需要测试和停止,您可能希望将while条件更改为其他条件。
发布于 2020-05-02 01:12:29
在Python中,您可以像这样使用线程睡眠。
import time
while True:
#Your Code
time.sleep(60)发布于 2020-05-02 01:15:17
首先,将所有代码放入一个函数中。然后使用线程模块的计时器功能,如下所示,在一定的时间间隔后重复该功能。
import threading
def your_function():
#your code inside function goes here. Make sure the below line is at last.
threading.Timer(5.0, your_function).start()
your_function
# continue with the rest of your code将5.0替换为所需的时间。
https://stackoverflow.com/questions/61547121
复制相似问题