Python 类型错误:“unicode”对象不可调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26760073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:58:49  来源:igfitidea点击:

TypeError: 'unicode' object is not callable

pythonseleniumunicodephantomjs

提问by MLSC

I want to get the source but I have the ERROR:

我想获得来源,但我有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

采纳答案by Lawrence Dean Vanderpool

page_source is not a method in the way you're using it. You want to use the get method on a url and then the driver will contain the source code you're looking for.

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

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

回答by viky.pat

This error occurs when we call unicode objects as a function. For example:

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

a = u'this is unicode string'

if you do a()somewhere in code you get this error

如果你a()在代码中做某处你会得到这个错误

In your case as pointed out page_sourceis a unicode string and not a callable function. So this page_source(url) is giving above error.

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