1

I would like run a specific moment a python script to show with selenium the chromium browser on DISPLAY :0.0 .

00 11 * * * pi export DISPLAY=:0.0 && "/usr/bin/python2.7 /home/pi/Desktop/script.py"

Example python script:

#!/usr/bin/python
# encoding=utf8
from selenium import webdriver

def main():
    options = webdriver.ChromeOptions()
    options.add_argument('--incognito')
    options.add_argument('--disable-gpu')
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    browser = webdriver.Chrome("/usr/bin/chromedriver",chrome_options=options)
    browser.get("www.google.com")

if __name__ == "__main__":
    main()

Could you please help me?

Francesco
  • 143
  • 1
  • 5

1 Answers1

2

First, the command with the quotes can't work:

"/usr/bin/python2.7 /home/pi/Desktop/script.py"

It might work without the quotes

/usr/bin/python2.7 /home/pi/Desktop/script.py

It depends on the X Server. It is likely that you will also need to set XAUTHORITY.

You can test this from the command line:

env -i DISPLAY=:0.0 /usr/bin/python2.7 /home/pi/Desktop/script.py

If this works, then your command should work if you remove the quote.

Otherwise try

env -i DISPLAY=:0.0 XAUTHORITY="$XAUTHORITY" /usr/bin/python2.7 /home/pi/Desktop/script.py

If this works, you need to set XAUTHORITY to the value of XAUTHORITY.

You may also need environment variables related to Python, like PYTHONSTARTUP, PYTHONHOME or PYTHONPATH.

RalfFriedl
  • 2,180
  • 2
  • 11
  • 12