Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

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

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")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  • Ensure that you are invoking:

    driver = webdriver.Chrome() # not webdriver.chrome()
    
  • 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:UsersAninditachromedriver.exe')
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...