What version of soupsieve do you have installed? The error seems to be with that library (which I am the author of). It’s complaining about the pseudo class, so I suspect you are on an older version that maybe still uses the old name :contains().
Just any FYI, soupsieve 2.1 is where the rename took place: https://facelessuser.github.io/soupsieve/selectors/pseudo-classes/#:-soup-contains.
I ran your snippet:
from bs4 import BeautifulSoup
import requests
page_source = requests.get('http://www.centrometeolombardo.com/content.asp?CatId=332&ContentType=Dati').text
soup = BeautifulSoup(page_source, 'lxml')
a = soup.select('table > tr:has(> td > a:-soup-contains("Bollate")) td')
print(a)
And I got this:
[<td align="left" height="1" width="45%">
<a href="http://www.centrometeolombardo.com/content.asp?contentid=7299&ContentType=Stazioni" target="_blank"><font color="#000080" face="Verdana" size="2"><b>Bollate</b></font></a>
</td>, <td align="center" height="4" width="8%"><font color="#000080" face="Verdana" size="2"><b>5.1</b></font></td>, <td align="center" height="4" width="8%"><font color="#000080" face="Verdana" size="2"><b>25.1</b></font></td>, <td align="center" height="4" width="27%"><font color="#000080" face="Verdana" size="2"><b>Pioggia</b></font></td>, <td align="center" height="1" width="8%"><font color="#000080" face="Verdana" size="2"><b>1.0</b></font></td>, <td align="center" height="1" width="8%"><font color="#000080" face="Verdana" size="2"><b>-</b></font></td>]
So, I’m not seeing your error. I’d double-check that what you are actually running is what you think you are running.
Unfortunately, this is beyond my expertise to give advice.
It is possible that you have multiple versions of Python and cron uses a different version than you are using in the terminal. Or maybe you have your libraries installed via pip as a user, and cron is running under root, so it accesses a different soupsieve?
My main concern, of course, is whether soupsieve is broken, which it appears it is not. If the correct versions of bs4 and soupsieve are used, there is no issue. I’m not sure what is going on with cron, I assume if you can figure out how to make available the expected versions of bs4 and soupsieve that your issues will be resolved.
A last question: would, in your opinion
-reinstall the os on raspberry
-install both cron and libraries with pip
solve the problem?
Any advice I could give at this point would be guessing. Without understanding the root cause, I would just be wasting your time.
I would try to do things like logging the python version and python path from cron to see if it is the same python being run. Do you use --user when installing packages as a user? If not maybe it isn’t a user vs root issue, or maybe it isn’t, or maybe it is more complicated than I think.
I, unfortunately, do not have any real good advice except to first try and understand what the issue is before making just wasting time guessing at solutions.