'Selenium on Raspberry Pi headless 2022

I have a weather station and take a screenshot of a webpage (windy.com) once an hour to integrate into my display which runs on a Pi 3

It was working perfectly until I had an SD card crash and had to rebuild it - I stupidly didn't have a backup of the SD card I now have Pi OS Bullseye, Python 3.9.2 and Selenium 4.1.3 This is the old program that was working on PI OS Buster with Python 3.7 and Selenium 1.9ish

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image
import pygame
options = Options()
options.headless = True
options.add_argument('--user-agent="Mozilla/5.0 (Windows NT x.y; rv:10.0) Gecko/20100101 Firefox/10.0"')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=options)
url = "https://embed.windy.com/embed2.html?lat=53.514&lon=-2.944&detailLat=53.393&detailLon=-2.134&width=530&height=490&zoom=4&level=surface&overlay=wind&product=ecmwf&menu=&message=true&marker=&calendar=now&pressure=true&type=map&location=coordinates&detail=&metricWind=mph&metricTemp=%C2%B0C&radarRange=-1"
driver.get(url)
driver.fullscreen_window()
driver.implicitly_wait(1)
driver.set_window_size(530,445)
driver.save_screenshot('weather.png')
basewidth = 530
img = Image.open('weather.png')
driver.quit()
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
img.save('/home/pi/images/weather_icons/kia.bmp')}

It will not work with the new Pi Bullseye, Python3.9 and Selenium 2.4 I had so many errors and gradually got rid of them all but now I'm left with this error and I cannot figure out how to fix it

This is the error

Traceback (most recent call last):
  File "/home/pi/map.py", line 6, in <module>
driver = webdriver.Chrome(service=s)
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
self.service.start()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
  File "/home/pi/.local/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /usr/lib/chromium-browser/chromium-browser-v7 unexpectedly exited. Status code was: -5

This is the modified code I had to use to get this far

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from PIL import Image
path = ('/usr/lib/chromium-browser')
s = Service('/usr/lib/chromium-browser/chromium-browser-v7')
driver = webdriver.Chrome(service=s)
options = webdriver.ChromeOptions()
options.set_capability("goog:loggingPrefs", {'performance': 'ALL'})
url = "https://embed.windy.com/embed2.html?lat=53.514&lon=-2.944&detailLat=53.393&detailLon=-2.134&width=530&height=490&zoom=4&level=surface&overlay=wind&product=ecmwf&menu=&message=true&marker=&calendar=now&pressure=true&type=map&location=coordinates&detail=&metricWind=mph&metricTemp=%C2%B0C&radarRange=-1"
driver.get(url)
driver.fullscreen_window()
driver.implicitly_wait(1)
driver.set_window_size(530,445)
driver.save_screenshot('weather.png')
basewidth = 530
img = Image.open('weather.png')
driver.quit()
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
img.save('/home/pi/images/weather_icons/kia.png')

My chromium-chromedriver is the latest version (98.0.4758) and my chromium browser is Version 98.0.4758.106

Can anyone tell me how to get this working without having to go back to the old versions of everything?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source