&是什么QUOT;模块对象不是可调用的"意思? [英] What does "module object is not callable" mean?
问题描述
我使用的是与机械化,这似乎打印出我想要的HTML .get_data()方法。我还要检查一下它打印出的类型,类型是'str的
I'm using the .get_data() method with mechanize, which appears to print out the html that I want. I also check the type of what it prints out, and the type is 'str'.
但是,当我尝试解析与BeautifulSoup的海峡,我得到以下错误:
But when I try to parse the str with BeautifulSoup, I get the following error:
---------------------------------------------------------------------------
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?
What exactly is 'module', and how do I get what get_data() returns into html?
推荐答案
在导入BeatufilulSoup是这样的:
When you import BeatufilulSoup like this:
import BeautifulSoup
您正在导入包含类,函数等。为了实例化一个BeautifulSoup类实例构成您需要或者导入它或使用全名,包括模块preFIX像yonili表明在该BeautifulSoup模块该模块以上评论:
You are importing the module which contains classes, functions etc. In order to instantiate a BeautifulSoup class instance form the BeautifulSoup module you need to either import it or use the full name including the module prefix like yonili suggests in the comment above:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
或
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(html)
这篇关于&是什么QUOT;模块对象不是可调用的&QUOT;意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!