在python selenium中调用phantomjs时出错

时间:2018-03-30 12:10:42

标签: python selenium selenium-webdriver webdriver phantomjs

from selenium import webdriver
drive = webdriver.phantomjs(executable_path='D:\python\scrapy\phantomjs-2.1.1-windows\bin\phantomjs.exe')
url='https://google.com'
drive.get(url)

当我运行这个python程序时:

drive = webdriver.phantomjs(executable_path='D:\python\scrapy\phantomjs-2.1.1-windows\bin\phantomjs.exe')

错误:

TypeError: 'module' object is not callable

1 个答案:

答案 0 :(得分:0)

通过调用 webdriver.PhantomJS() ,可以创建 PhantomJS / Ghostdriver 的新实例。因此,您需要将代码更改为:

from selenium import webdriver

drive = webdriver.PhantomJS(executable_path=r'D:\python\scrapy\phantomjs-2.1.1-windows\bin\phantomjs.exe')
url='https://google.com'
drive.get(url)