“module object is not callable”是什么意思?

4

我正在使用机械浏览器的.get_data()方法,似乎它会打印出我想要的html内容。我还检查了它打印出的类型,类型为'str'。

但是当我尝试使用BeautifulSoup解析这个字符串时,就会出现以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-163-11c061bf6c04> in <module>()
      7     html = get_html(first[i],last[i])
      8     print type(html)
----> 9     print parse_page(html)
     10 #     l_to_store.append(parse_page(html))
     11 # hfb_data['l_to_store']=l_to_store

<ipython-input-161-bedc1ba19b10> in parse_hfb_page(html)
      3     parse html to extract info in connection with a particular person
      4     '''
----> 5     soup = BeautifulSoup(html)
      6     for el in soup.find_all('li'):
      7         if el.find('span').contents[0]=='Item:':

TypeError: 'module' object is not callable

'模块'到底是什么,如何将get_data()返回的内容嵌入HTML中?


4
尝试:BeautifulSoup.BeautifulSoup(html) - yonili
1个回答

8
当你像这样导入BeautifulSoup时:

import BeautifulSoup

import BeautifulSoup

您正在导入包含类、函数等的模块。要实例化来自BeautifulSoup模块的BeautifulSoup类实例,您需要导入它或使用包括模块前缀的完整名称,就像yonili在上面的评论中建议的那样:

from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)

或者

import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(html)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接