*/5 * * * * /bin/php /home/project/hello.php
5分钟执行一次5minute run
有显示执行任务 run python display
30 5 * * * export DISPLAY=:0; /home/me/good_morning.sh
我的电脑任务 my serveur linux
5 8 */1 * * /usr/bin/python3 /root/guo/caiji_wordpress_chinanews_ok.py >> /root/guo/cron-caiji.log 2>&1
合成任务 cron.sh is ok
*/5 * * * * export DISPLAY=:0; /usr/bin/python3 /root/tor.py >> /root/tor.log 2>&1
==========================================
创建脚本 安装python3 -m pip install pyvirtualdisplay
This issue has bugged me for near 6 hours.
So if I write /usr/bin/python3 -u /root/apps/bridge/cinkselenium.py in terminal it is working fine.
But it doesn’t work for crontab. Right?
Adding for tor.py
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
will not help.
What you need is to make a shell script and write the following –
cron.sh = chmod +x cron.sh
#!/usr/bin/env bash
export DISPLAY=:0
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
nohup /usr/bin/python3 -u /root/tor.py > /root/tor.log &y
Now run the shell script from Crontab -e
* * * * * /root/cron.sh
This is what works properly for selenium in crontab without headache in DigitalOcean servers. The paths will be different based on your server and program location.
share improve this answer follow


未经允许不得转载:萌萌guo angline - Apprentissage » run crontab with python selenium tor browser display in linux


linux一键中文脚本
google shell启用增强模式4核16G内存
使用python批量爬取主流搜索引擎图片
python爬虫关键词爬取百度的图片
python库taichi太极人工智能tensoflow图形处理
Selenium with Tor Browser using Python
