I'm putting errors in Try and Except, but I'm having trouble with 2 types of errors. I'll give you an example of what I need. This except with Valure Error works fine, because I know the error is called ValueError, so:
#ONLY EXAMPLE
except ValueError:
return "FAILED"
EXCEPT ERROR N.1 The question I ask you is: how should I write for the following error? It consists of the wrong name of an html class when scraping. I wrote selenium.common.exceptions.NoSuchElementException, but the error search does not work (the script does not open at all)
except selenium.common.exceptions.NoSuchElementException:
return "FAILED"
EXCEPT ERROR N.2 Same thing for the database insert error. I want to make sure that if 0 records are saved in the database then I have an error. I tried to write like this, but it's not good:
except records_added_Results = records_added_Results = + 0:
return "FAILED"
I wrote this because I have this code for the insertion in the database. It works correctly, I am writing it just to make you understand:
con = sqlite3.connect('/home/mypc/Scrivania/folder/Database.db')
cursor = con.cursor()
records_added_Results = 0
Values = ((SerieA_text,), (SerieB_text,)
sqlite_insert_query = 'INSERT INTO ARCHIVIO_Campionati (Nome_Campionato) VALUES (?);'
count = cursor.executemany(sqlite_insert_query, Values)
con.commit()
print("Record inserted successfully ", cursor.rowcount)
records_added_Results = records_added_Results + 1
cursor.close()
How should I write? Thank you