Skip to main content
 首页 » 编程设计

Python/解析 : BeautifulSoup error "module obj is not callable" with results from Mechanize

2025年05月04日12jyk

BeautifulSoup 和我无法识别 br.response().read() 的结果。 我导入了 BeautifulSoup

#snippet: 
# Select the first (index zero) form 
br.select_form(nr=0) 
br.form.set_all_readonly(False) 
br['__EVENTTARGET'] = list_of_dates[0] 
br['__EVENTARGUMENT'] = 'calMain' 
br['__VIEWSTATE'] = viewstate 
br['__EVENTVALIDATION'] = eventvalidation 
 
response = br.submit() 
print br.response().read() #*#this prints the html I'm expecting* 
 
soup = BeautifulSoup(br.response().read()) #*#but this throws  
#TypeError: 'module' object is not callable.   
#Yet if I call soup = BeautifulSoup("http://page.com"), it's cool.* 
 
selecttable = soup.find('table',{'id':"tblItems"}) 
#/snippet 

...等等

所以我明白我有错误的“对象”,但是,BeautifulSoup 想要什么样的“对象”?

请您参考如下方法:

使用

from BeautifulSoup import BeautifulSoup 

代替

import BeautifulSoup 

否则我认为你做的是对的!