MLS*_*LSC 6 python unicode selenium phantomjs
我想获得来源,但我有ERROR:
>> from selenium import webdriver
>> driver = webdriver.PhantomJS()
>> url='http://google.com'
>> cont=driver.page_source(url)
>> print cont
>> driver.quit()
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "u.py", line 6, in <module>
cont=driver.page_source(url)
TypeError: 'unicode' object is not callable
Run Code Online (Sandbox Code Playgroud)
当我们将 unicode 对象作为函数调用时,就会出现此错误。例如:
a = u'this is unicode string'
Run Code Online (Sandbox Code Playgroud)
如果你a()在代码中做某事,你会得到这个错误
在你的情况下,正如所指出的那样,page_source它是一个 unicode 字符串,而不是一个可调用函数。所以这个page_source(url) 给出了上面的错误。
page_source 不是您使用它的方式的方法。您想要在 url 上使用 get 方法,然后驱动程序将包含您要查找的源代码。
>> from selenium import webdriver
>> driver = webdriver.PhantomJS()
>> url='http://google.com'
>> driver.get(url)
>> print driver.page_source
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41557 次 |
| 最近记录: |