TypeError: 'module' object is not callable error with driver=webdriver("C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe")

TypeError: 'module' object is not callable error with driver=webdriver(

问题描述:

我收到了类似 Pycharm 的错误:

I am getting an error like in Pycharm:

Traceback (most recent call last):   
File "C:/PycharmProjects/DemoPyth/PythonPack1/Prg1.py", line 3, in <module>     
driver=webdriver("C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe") 
TypeError: 'module' object is not callable. 

我的脚本很简单:

from selenium import webdriver   
driver=webdriver.Chrome("C:\Python34\Lib\site-packages\selenium\webdriver\chromedriver.exe")

根据最佳实践,您不得添加/删除/修改任何目录/子目录/文件Python创建,直到和除非您知道更改将如何影响 Python 的行为.

As per best practices you must not add/delete/modify any of the directories / sub-directories / files created by Python until and unless you are aware how the change is going to effect Python's behavior.

您需要从下载最新的ChromeDriverChromeDriver - 适用于 Chrome 的 WebDriver 并将其存储在您系统中的任何位置.当您使用 Windows 操作系统 时,解压缩二进制文件并执行以下操作:

You need to download the latest ChromeDriver from ChromeDriver - WebDriver for Chrome and store it anywhere within your system. As you are on Windows OS, unzip the binary and perform the following:

  • 确保您正在调用:

  • Ensure that you are invoking:

driver = webdriver.Chrome() # not webdriver.chrome()

  • 在您的程序中,将 Key executable_pathValue 一起传递给绝对路径 ChromeDriver 的.

  • Within your program, pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver.

    所以你的代码块将是:

    from selenium import webdriver
    
    driver=webdriver.Chrome(executable_path=r'C:UsersAninditachromedriver.exe')