Execute Python scripts with Selenium via Crontab Execute Python scripts with Selenium via Crontab selenium selenium

Execute Python scripts with Selenium via Crontab


The problem concerns environment variables: cron is started by the system and knows nothing about user environments.

So, the solution to a problem is to make cron run a shell script that sets the needed environment variables first and then runs the script. In my case I needed to set the PATH varibable like this: PATH=/root/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binAlso, it may be useful to set HOME or DISPLAY varibles in some cases.


Try a hardcoded Firefox binaryhttps://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_binary.html

selenium.webdriver.firefox.firefox_binary.FirefoxBinary("/your/binary/location/firefox")driver = webdriver.Firefox(firefox_binary=binary)