TypeError:“ FirefoxWebElement”对象不支持索引

时间:2019-03-08 08:29:24

标签: python selenium selenium-webdriver geckodriver

我正在尝试用股票行情清单搜索纳斯达克网站。我想发生的是,在for循环中,我想逐个循环显示报价器,并提取“每股收益”数据点。这是重要的代码:

for i in range(len(data)):
    inputz.send_keys(data[i]["ticker"])
    btnz.click()
    time.sleep(4)
    linkz = driver.find_element_by_id("summaryquotelink")
    linkz.click()
    data = driver.find_element_by_xpath("/html/body/div[1]/div[1]/div[2]/div[8]/div[1]/div[2]/div/div[3]/div[2]")
    print(type(data.text))
    earningsPerShare = data.text
    print(earningsPerShare)

它提取第一次迭代的数据,但是在涉及第二个列表对象时抛出错误。

编辑网址:https://www.nasdaq.com

完全追溯

Traceback (most recent call last):
File "C:/Users/Stevesy/PycharmProjects/FirstSeleniumTest/test/Test1.py", line 20, in <module>
    inputz.send_keys(data[i]["ticker"])
TypeError: 'FirefoxWebElement' object does not support indexing

数据是json文件:

with open('items.json','r') as read_file:
    data = json.loads(read_file.read())

0 个答案:

没有答案