Mechanize 错误与

1 投票
1 回答
557 浏览
提问于 2025-04-18 07:00

我安装了Python 2.7、BeautifulSoup和mechanize。但是我无法打开网页,出现了这样的提示:

<response_seek_wrapper at 0x2d89348L whose wrapped object =<closeable_response at 0x2d89988Lwhose fp = <socket._fileobjectobject at 0x0000000002D4CE58>>>

这是我的代码:

import mechanize
br=mechanize.Browser()
url = 'http://www.google.com' (or any other)
br.open(url)

我试着在谷歌上搜索这个错误信息,但找不到任何相关内容。感觉好像缺少了什么,但我看了很多教程和论坛,他们都直接使用打开网页的方法,没有准备虚拟浏览器。我尝试了IDLE和命令提示符,但得到的提示都是一样的。我的操作系统是Windows 7。

我这里缺少了什么呢?

1 个回答

0

这并不意味着它没有工作。它会打开页面并返回一个 response 对象,但你不需要使用这个对象。只需在调用 open() 后继续使用 br 即可:

>>> import mechanize
>>> br = mechanize.Browser()
>>> url = 'http://www.google.com'
>>> br.open(url)
<response_seek_wrapper at 0x11164ed88 whose wrapped object = <closeable_response at 0x111653320 whose fp = <socket._fileobject object at 0x111648250>>>
>>> br.title()
'Google'

撰写回答