Crontab python3-selenium未运行任务:

1 投票
1 回答
930 浏览
提问于 2025-06-18 04:12

我正在尝试定期运行一个带有显示界面的 Selenium Python 脚本,但这个脚本并没有执行。运行一些简单的任务显示定时任务(cron)是有效的,但同样的方法在 Python3/Selenium 脚本上却不奏效。我的 crontab -l 输出是:

SHELL=/bin/bash
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                       7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command_to_execute

12 18 * 5-8 1-5 export DISPLAY=:0; /Users/eshauchuk/opt/anaconda3/bin/python3 /Users/eshauchuk/checkout.py

12 18 * 5-8 1-5 /Users/eshauchuk/opt/anaconda3/bin/python3 /Users/eshauchuk/checkout.py

此外,我提到过脚本应该在 bash 中运行,并且需要显示界面,但到目前为止都没有成功。如果能得到任何帮助,我将非常感激!

相关问题:

  • 暂无相关问题
暂无标签

1 个回答

1

通过同时指定 DISPLAY 和 PATH 解决了这个问题:

* * * * * export DISPLAY=:0 && export PATH=$PATH:/usr/local/bin && /Users/username/opt/anaconda3/bin/python3 /Users/username/checkout.py >> crontab.txt

使用 Anaconda 的 Python

撰写回答