Home > Mobile >  problem with inserting the data from selenium into the dictionary in python
problem with inserting the data from selenium into the dictionary in python

Time:07-01

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 selenium.webdriver.common.by import By

titledic ={}
browser = webdriver.Chrome()
browser.get('https://www.cbc.ca/news')
browser.implicitly_wait(10)
result = browser.find_elements(By.CLASS_NAME, 'card-content-top')
for items in result:
    titledic{items} = items.text ```

CodePudding user response:

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
  • Related