[Mechanize.ClientForm] double reading from urllib2.urlopen

tiktak.hodiki at gmail.com tiktak.hodiki at gmail.com
Wed Jan 7 13:49:26 EST 2009


Hello, folks!
I use mechanize.clientform to parse HTML-forms. I preliminary check
response and call response.read().find("..."). But when it's taken to
ClientForm.ParseResponse, it can't parse because of response.read() is
zero-length text. The problem is that ClientForm.ParseResponse is not
taken text of response, only object.

Example:

import urllib
from ClientForm import ParseResponse
response = urllib.urlopen("http://yandex.ru")
if -1 != response.read().find("foobar"):
    pass
form = ParseResponse(response)[1] <-- there is exception IndexError



More information about the Python-list mailing list