【发布时间】:2012-06-09 20:00:36
【问题描述】:
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 想要什么样的“对象”?
【问题讨论】:
-
你用什么import语句来导入美汤?
-
您更新的脚本再次执行 br.response.read() 两次。您需要致电
BeautifulSoup(raw)。你应该只调用一次 response.read 。此外,您可能不应该调用模块对象,而应该在响应对象上调用它。 -
所以我已经完全去掉了“cooked”,现在调用 BeautifulSoup(raw)。现在用一些非虚拟数据对此进行测试。谢谢!!
标签: python beautifulsoup mechanize