0

for a private project I'm trying to make my python script, running on a raspberry, to capture the current traffic situation on Google Maps.

When first opening the gmaps site, several questions where asked about personal preferences (and saved as cookies afterwards). I managed this problem with the script below - which works prefectly when started in Thonny.

It behaves differently though when started with the command bar or cron tab. It seems like the web driver is not loading the saved options anymore: The link starts with the google-option-page again.

Why does the script behave differently?

from datetime import datetime
from selenium.webdriver.chrome.options import Options
now = datetime.now()

chrome_options = Options()
chrome_options.add_argument('user-data-dir=selenium')

driver = webdriver.Chrome(options=chrome_options, executable_path=r'/home/pi/Documents/chromium/chromedriver')
driver.maximize_window()
driver.implicitly_wait(2)

driver.get('https://www.google.com/maps/@48.835072,9.121823,14z/data=!5m1!1e1')

filename = now.strftime('%Y.%m.%d %H.%M')
driver.save_screenshot(f'/home/pi/Documents/GMaps/{filename}.png')
driver.close()```

1 Answers1

0

Thanks to StackOverflow, I found a solution: Obviously Scripts ran by Thonny, command bar and crontab use different environment variables. The webdriver does not start using crontab, unless a DISPLAY variable is set:

https://stackoverflow.com/a/66468045/10332200