Hi Python users,

I have a question about the instance of closeable_response in module Mechanize.

        from mechanize import ParseResponse, urlopen
        url = "http://wwwsearch.sourceforge.net/mechanize/example.html";
        r = urlopen(url)
        forms = ParseResponse(r, backwards_compat=False)
        html_lines = r.read()

If I call ParseResponse() before r.read(), then lforms would be a list 
containing one form 
instance, and html_lines would be an empty string. If I call r.read() first, 
then html_lines 
would be the HTML source code of the page, but forms would be an empty list. 

Therefore, I have to open the url twice, once for each function, like this:

        r = urlopen(url)
        forms = ParseResponse(r, backwards_compat=False)
        r = urlopen(url)
        html_lines = r.read()

I believe this shouldn't be necessary. What is the proper way of doing it? 
Thank you.

- Yingjie







-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to