Submitting Nested Form With Python Mechanize
I am trying to submit a login form on a web page that looks something like this. I have also tried submit the nested form as well as submit both forms, same error every time.
Solution 1:
Try using the ICantBelieveItsBeautifulSoup or MinimalSoup parser instead of BeautifulSoup, see Is it possible to hook up a more robust HTML parser to Python mechanize? for implementation
Solution 2:
You can try looking for the offending section of the page and adjusting it manually. For example I had a page that was getting the nested forms issue and I found that there was
<FORM></FORM>
sitting inside another form block. I also needed to remove the first line because that was also formatted badly. So you could try something like this:
...
resp = br.open(url) # Load login page# the [111:0] takes away the first 111 chars of the response# the .replace('<FORM></FORM>','') removes the bad HTML
resp.set_data(resp.get_data()[111:].replace('<FORM></FORM>',''))
br.set_response(resp)
Post a Comment for "Submitting Nested Form With Python Mechanize"