我使用斜纹布(0.9),我还想访问它的内置机械分布(在 Python 2.6.6 上)。我阅读了所有文档,但我不清楚他们是否支持或推荐,如果是,他们当然不会公开它。看来你可以这样做:
import _mechanize_dist as mechanize
br = mechanize.Browser()
br.open('http://www.yahoo.com')
但是mechanize 会在下面抛出愚蠢的 AttributeErrorrobotparser._debug。我不应该尝试使用它吗?还是只是机械化处理草率的异常?(斜纹布本身工作正常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'
(最后一个问题是:我不知道并排使用 twill 和 mechanize 命令的任何警告?)