Joe Schmoe
Joe Schmoe

Reputation: 2083

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 are 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?

Upvotes: 0

Views: 869

Answers (1)

Joe Schmoe
Joe Schmoe

Reputation: 2083

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)

Upvotes: 2

Related Questions