2013-12-07 43 views
3

我使用.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?

+3

嘗試:'BeautifulSoup.BeautifulSoup(html)' – yonili

回答

3

當您導入BeatufilulSoup這樣的:

import BeautifulSoup 

要導入其中包含的類,函數等。爲了實例化一個BeautifulSoup類實例形成你需要或者導入或使用BeautifulSoup模塊該模塊全名,包括像yonili模塊前綴表明在上面的評論:

from BeautifulSoup import BeautifulSoup 
soup = BeautifulSoup(html) 

import BeautifulSoup 
soup = BeautifulSoup.BeautifulSoup(html) 
+0

哦,天哪,我通常這樣做。儘管如此,我永遠不會想到。感謝Bernhard的幫助 – goldisfine