Help on instance of closeable_response in module Mechanize
Yingjie Lin
Yingjie.Lin at mssm.edu
Mon Aug 22 20:17:47 EDT 2011
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
More information about the Python-list
mailing list