problem with inserting the data from selenium into the dictionary in python


I am practicing selenium and I already grabbed the data from a website, I’d like to insert them into a dictionary, I created an empty dictionary and looped through all the elements but I can’t push the data into the dictionary,
It gives me an error that can’t assign to literals, any suggestion on how I can solve this problem?

from selenium.webdriver.common import keys
from selenium.common.exceptions import NoSuchElementException
from import By

titledic ={}
browser = webdriver.Chrome()
result = browser.find_elements(By.CLASS_NAME, 'card-content-top')
for items in result:
    titledic{items} = items.text ```


Maybe it’s because you used curly brackets instead of square brackets when updating the dictionary.

Try this:

# the rest of your code

for items in result:
    titledic[items] = items.text

Answered By – Jordan

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published