我使用 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 .我不应该尝试使用它吗?或者它只是 Mechanize 的草率异常处理?(斜纹本身工作正常:
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'
(最后一个问题是:我不知道有关同时使用斜纹和 Mechanize 命令的任何警告?)
最佳答案
目前用斜纹布运输的 Mechanize 分布很古老。
最近在twill mailing list上有事件关于升级它。
关于python - 使用 twill 的内置 Mechanize 分布会在 _debug 上引发 AttributeError 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7278103/