我使用 twill (0.9),我还想访问其内置的 mechanize 发行版(在Python 2.6.6上)。 我阅读了所有文档,我不清楚他们是否支持或建议,如果是这样,他们肯定不会公开它。 看来你可以做到:
import _mechanize_dist as mechanize
br = mechanize.Browser()
br.open('http://www.yahoo.com')
然而 mechanize会在robotparser._debug
下面抛出下面的愚蠢的AttributeError。我不应该尝试使用它吗?还是机械化只是草率的异常处理?
(斜纹本身可以正常工作:twill.commands.go('http://www.yahoo.com')
)
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
br.open('http://www.yahoo.com')
File "C:\Dev\Python26\lib\site-packages\twill-0.9-py2.6.egg\twill\other_packages\_mechanize_dist\_mechanize.py", line 212, in open
return self._mech_open(url, data)
File "C:\Dev\Python26\lib\site-packages\twill-0.9-py2.6.egg\twill\other_packages\_mechanize_dist\_mechanize.py", line 238, in _mech_open
response = UserAgentBase.open(self, request, data)
File "C:\Dev\Python26\lib\site-packages\twill-0.9-py2.6.egg\twill\other_packages\_mechanize_dist\_opener.py", line 175, in open
req = meth(req)
File "C:\Dev\Python26\lib\site-packages\twill-0.9-py2.6.egg\twill\other_packages\_mechanize_dist\_http.py", line 440, in http_request
self.rfp.read()
File "C:\Dev\Python26\lib\site-packages\twill-0.9-py2.6.egg\twill\other_packages\_mechanize_dist\_http.py", line 387, in read
robotparser._debug("parse lines")
AttributeError: 'module' object has no attribute '_debug'
(最后一个问题是:我不知道有关并排使用斜纹和机械化命令的任何警告吗?)