str'对象不可调用

1 投票
2 回答
1508 浏览
提问于 2025-04-16 23:09

我不太明白为什么会出现这个追踪错误:

Traceback (most recent call last):
  File "S:/Personal Folders/Andy/Python Projects/Salesforce BZ API/Automated Reports.py", line 15, in <module>
    parse = br.soup("find('div')")
  File "build\bdist.win32\egg\spynner\browser.py", line 409, in _get_soup
    return self._html_parser(self.html)
TypeError: 'str' object is not callable

这是我的代码:

from __future__ import division
#from __future__ import unicode_literals
from __future__ import print_function
import spynner
from BeautifulSoup import BeautifulSoup

#Loading up Salesforce

br = spynner.Browser()
#br.debug_level = spynner.DEBUG
br.create_webview()
br.show()
br.set_html_parser("BeautifulSoup")
br.load("https://login.salesforce.com/")
parse = br.soup("find('div')")
print(parse)
br.browse()
br.close()

2 个回答

0

我简单看了一下这里,似乎soup不是一个函数,而是一个属性。

5

看起来你把HTML解析器设置成了字符串“BeautifulSoup”,而不是实际的BeautifulSoup库。我没有安装这个库,所以无法测试它是否有效,但你可以试试看。

撰写回答