Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误:必须使用phantomJs使用WebDriver调用解除绑定的方法get()_Python_Selenium - Fatal编程技术网

Python 错误:必须使用phantomJs使用WebDriver调用解除绑定的方法get()

Python 错误:必须使用phantomJs使用WebDriver调用解除绑定的方法get(),python,selenium,Python,Selenium,我按照stackoverflow上的建议代码进行操作,但出现了一个错误: unbound method get() must be called with WebDriver instance as first argument (got str instance instead) 我的代码是: >>> from selenium import webdriver >>> import time >>> from bs4 import *

我按照
stackoverflow
上的建议代码进行操作,但出现了一个错误:

unbound method get() must be called with WebDriver instance as first argument (got str instance instead)
我的代码是:

>>> from selenium import webdriver
>>> import time
>>> from bs4 import *
>>> sns_sources = 'www.abc.com'
>>> driver = webdriver.PhantomJS
>>> driver.get(sns_sources)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unbound method get() must be called with WebDriver instance as first argument (got str instance instead)
来自selenium导入webdriver的
>
>>>导入时间
>>>从bs4导入*
>>>sns_来源='www.abc.com'
>>>driver=webdriver.PhantomJS
>>>获取驱动程序(sns_源)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:必须使用WebDriver实例作为第一个参数调用未绑定的方法get()(改为使用get-str实例)

只需正确创建PhantomJS实例即可

from selenium import webdriver
import time
from bs4 import *
sns_sources = 'www.abc.com'
driver = webdriver.PhantomJS()
driver.get(sns_sources)

您没有实例化
PhantomJS
,因此
driver
只是类
webdriver.PhantomJS
的另一个名称。如果不将实例作为第一个参数传递,则不能直接对类调用
.get()