Selenium错误:AttributeError:'WebDriver'对象没有属性'Firefox'

时间:2019-03-23 17:01:20

标签: python python-2.7 selenium geckodriver

我正在尝试运行下面的代码,我认为该代码可以正常工作,但实际上却出现此错误:

AttributeError:“ WebDriver”对象没有属性“ Firefox”

def main():
    import csv
    import os
    import selenium
    from selenium import webdriver
    profile = webdriver.FirefoxProfile()
    profile.accept_untrusted_certs = True
    wd = webdriver.Firefox(executable_path="C:/Utility/geckodriver.exe", firefox_profile=profile)

    ticker = input("Enter your ticker: ")
    url = "http://financials.morningstar.com/cash-flow/cf.html?t=" + ticker.upper()
    print(url)

    browser = wd.Firefox()
    browser.get(url)

    values_elementticker = browser.find_elements_by_xpath("//span[@class='gry']")
    values2 = values = [x.text for x in values_elementticker]
    print(values2[0])

    values_element = browser.find_elements_by_xpath("//div[@id='data_i97']")
    values = [x.text for x in values_element]
    print("Cash Flows:")
    print(values[0])

    with open("C:\\Users\\Excel\\Desktop\\results.xls", "a") as f:
        for i in range(len(values2)):
            f.write(values2[0] + "\n")
        for i in range(len(values)):
            f.write(values[0] + "\n")

    browser.close()
    restart = input("Do you wish to start again?").lower()
    if restart == "yes":
        main()

    else:
        exit()
main()

输入有效的置顶后,立即引发错误。这对别人有用吗?或者,代码有问题吗?在我看来还可以。谢谢。

0 个答案:

没有答案