Python/parsing:beauthulsoup错误“module obj is not callable”(模块对象不可调用),结果来自Mechaniz

2024-10-01 17:23:32 发布

您现在位置:Python中文网/ 问答频道 /正文

更新:哇,你们都是对的!
出于我还不明白的原因,我需要: “从BeautifulSoup导入BeautifulSoup” 以及添加行:

response = br.submit()
print type(response) #new line
raw = br.response().read()#new line
print type(raw)#new line
print type(br.response().read())#new line
cooked = (br.response().read())#new line
soup = BeautifulSoup(cooked)

/更新

嗯,我和Beautulsoup没有意识到br.响应()。读取()。 我进口了美体素 ... 在

^{pr2}$

。。。等等

所以我觉得我的“对象”是错误的,但是,伙计,你认为美丽集团想要什么样的“对象”?在

干杯,谢谢!!在


Tags: 对象brnewreadrawresponsetypeline
3条回答

使用

from BeautifulSoup import BeautifulSoup

而不是

^{2}$

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

你写道:

response = br.submit()
print br.response().read() #*#this prints the html I'm expecting*

soup = BeautifulSoup(br.response().read())

你为什么不试试:

^{2}$

我怀疑这与您在br.response()上调用.read()有关,在我使用mechanize的历史中,我总是将response()保存到一个变量中,并从那里调用.read()。我不知道它会起作用,也不能很好地解释为什么print br.response().read()会起作用,但请试一试。在

另外,beauthoulsoup的HTML解析器可能不喜欢mechanize提供给它的内容。您可以尝试使用a different parser。在

只需确认您的导入如下所示:

from BeautifulSoup import BeautifulSoup

或是为了美丽之旅

^{2}$

相关问题 更多 >

    热门问题