Run selenium using crontab (python)

I have a python script that calls chrome through selenium with the following line.

 ff = webdriver.Chrome('/home/user01/webScraping/CollectAndGo/chromedriver')

The python script is invoked from a shell script.

python /home/user01/webScraping/CollectAndGo/cgcom.py > /home/user01/webScraping/CollectAndGo/cgcom.log 2>&1

When I run the script from the terminal or just execute the .sh file, it works fine, but when I plan to run crontab, it fails with the following error.

   raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'unknown error: Chrome failed to start: exited abnormally\n  (Driver info: chromedriver=2.9.248304,platform=Linux 3.5.0-36-generic x86_64)' 

The error is related to the first line of code for this question. Does anyone know why this might happen?

+5
source share
3 answers

cron , X, DISPLAY , crontab, .

. , , X, DISPLAY :0, X- , Ubuntu.

, command crontab, Chrome :

DISPLAY=:0 google-chrome

crontab :

0 * * * *  DISPLAY=:0 google-chrome

Python, chrome selenium, :

0 * * * *  DISPLAY=:0 python my_script.py

, DISPLAY=:0 python my_script.py . , , . (, , dash bash, , , .) , , DISPLAY :0 python my_script.py. python , , DISPLAY :0.

DISPLAY=:0, , . DISPLAY :0 , crontab. , crontab:

DISPLAY=:0

30 * * * *  google-chrome
0  * * * *  python my_script.py

DISPLAY=:0 DISPLAY google-chrome, python my_script.py

+8

Crontab , / .

, crontab .

0

- selenium X- script. Cron X . X- cron script. : * 11 * * * export DISPLAY =: 0; script.py

0
source

Source: https://habr.com/ru/post/1542300/


All Articles