TypeError: 'module' object is not callable

2019-03-01 11:31发布

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. 

My script is a simple one :

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

1条回答
祖国的老花朵
2楼-- · 2019-03-01 12:09

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.

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:

  • Within your program, pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver.
  • While mentioning the absolute path of the ChromeDriver, either use double back slashes i.e. \\ within double quotes i.e. " "
  • Or use single back slash i.e. \ within single quotes i.e. ' ' along with the raw r switch as follows.
  • So your code block will be:

    from selenium import webdriver
    
    driver=webdriver.Chrome(executable_path=r'C:\Users\Anindita\chromedriver.exe')
    
查看更多
登录 后发表回答