【问题标题】:problem with inserting the data from selenium into the dictionary in python将硒中的数据插入python中的字典的问题
【发布时间】:2022-07-01 00:54:32
【问题描述】:

我正在练习 selenium,我已经从网站上抓取了数据,我想将它们插入字典中,我创建了一个空字典并循环遍历所有元素,但我无法将数据推送到字典中, 它给了我一个无法分配给文字的错误,有什么建议可以解决这个问题吗?

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 ```

【问题讨论】:

  • some_dictionary['some_key']

标签: python selenium selenium-webdriver


【解决方案1】:

可能是因为您在更新字典时使用了大括号而不是方括号。

试试这个:

# the rest of your code

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    • 2020-02-04
    • 1970-01-01
    相关资源
    最近更新 更多