python's mechanize wont properly parse a form
I'm trying to submit a form using python's mechanize but it wont properly parse the form in question. There are 4 other forms, which 开发者_如何学Pythonare parsed correctly except for this one form. The form is properly parsed in perl's www::mechanize though but i'd like to stick with python.
Is there anyway of retrieving the html of the page and editing it and get mechanize to parse and submit the form based on the retrieved HTML?
If anyone else is interested. Found the answer in mechanize's FAQ.
Alternatively, you can process the HTML (and headers) arbitrarily:
browser = mechanize.Browser()
browser.open("http://example.com/")
html = browser.response().get_data().replace("<br/>", "<br />")
response = mechanize.make_response(
html, [("Content-Type", "text/html")],
"http://example.com/", 200, "OK")
browser.set_response(response)
精彩评论