【发布时间】:2017-03-30 09:43:55
【问题描述】:
我正在从每天早上更新的网页中获取数据,该网页在不同的时间更新,我想知道如何让脚本每 10 分钟左右运行一次以检查网站是否已更新。我正在考虑以某种方式使用 cron,但我不太了解它。感谢您的帮助。
【问题讨论】:
标签: python python-3.x cron
我正在从每天早上更新的网页中获取数据,该网页在不同的时间更新,我想知道如何让脚本每 10 分钟左右运行一次以检查网站是否已更新。我正在考虑以某种方式使用 cron,但我不太了解它。感谢您的帮助。
【问题讨论】:
标签: python python-3.x cron
您是否尝试过使用包 APScheduler?它使安排任务变得相当简单。这里是the documentation。
要做一个计划任务,这就是所有需要做的事情(对于一些基本的事情):
from apscheduler.schedulers.background import BackgroundScheduler
from pytz import utc
scheduler = BackgroundScheduler()
scheduler.configure(timezone=utc)
def print_hello():
print("Hello, this is a scheduled event!")
job = scheduler.add_job(print_hello, 'interval', minutes=1, max_instances=10)
scheduler.start()
但是请注意,当我第一次尝试使用该库时,我遇到了一个小错误,但有关如何修复该问题的说明是 here。
【讨论】: