TypeError:'unicode'对象不可调用

时间:2014-11-05 14:50:43

标签: python selenium unicode phantomjs

我想获得来源,但我有ERROR

>> from selenium import webdriver
>> driver = webdriver.PhantomJS()
>> url='http://google.com'
>> cont=driver.page_source(url)
>> print cont
>> driver.quit()

ERROR:

Traceback (most recent call last):
  File "u.py", line 6, in <module>
    cont=driver.page_source(url)
TypeError: 'unicode' object is not callable

2 个答案:

答案 0 :(得分:3)

page_source不是您使用它的方法。您想在网址上使用get方法,然后驱动程序将包含您正在寻找的源代码。

>> from selenium import webdriver
>> driver = webdriver.PhantomJS()
>> url='http://google.com'
>> driver.get(url)
>> print driver.page_source

答案 1 :(得分:3)

当我们将unicode对象作为函数调用时,会发生此错误。例如:

a = u'this is unicode string'

如果你在代码的某处a()出现了这个错误

在你指出的情况下,page_source是一个unicode字符串,而不是一个可调用的函数。所以这个page_source(url)给出了上述错误。