I use twill (0.9) and I want to also access its builtin mechanize distribution (on Python 2.6.6). I read all the documentation and I'm not clear whether they even support or recommend that, if so they certainly don't publicize it. It seems you can do:
import _mechanize_dist as mechanize
br = mechanize.Browser()
br.open('http://www.yahoo.com')
however mechanize throws the stupid AttributeError below on robotparser._debug
. Should I not be trying to use it? or is it just sloppy exception handling by mechanize?
(Twill itself works fine: 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\_mechani开发者_如何学Pythonze_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'
(Last question is: I'm not aware of any caveats about using both twill and mechanize commands side-by-side?)
The distribution of mechanize currently shipped with twill is ancient. Recently there has been activity on twill mailing list about upgrading it.
精彩评论