0

i have a form which is used for authentication. but in this form there are no submit button but it has used an <input> as a button . now i am confused how to click this type of button with MECHANIZE.

page details

till now i had done this:

import urllib
import re
import mechanize
from base64 import b64encode

and can this be done in Java script?

br = mechanize.Browser()


response = br.open("http://xyz.com");
#print response.code
#print response.geturl()

br.select_form("login")
br.form['j_username'] = 'user'
br.form['j_password'] = 'pass'
6
  • br.form.submit() doesn't work? Commented Aug 29, 2013 at 21:42
  • there is no method of br.form.sumbit() but after selecting the form we can submit the form by br.form() but it is giving this error: <response_seek_wrapper at 0x2d693a0 whose wrapped object = <closeable_response at 0x2d86fd0 whose fp = <socket._fileobject object at 0x02D7DA30>>> Commented Aug 29, 2013 at 21:49
  • Sorry, I meant br.submit. See here and here Commented Aug 29, 2013 at 21:52
  • br.submit() should return another webpage but it returning some different thing which i have described in above comment. Commented Aug 29, 2013 at 22:00
  • 1
    That's not an error. Read the response - it's a filelike object. response = br.form.submit() html = response.read() Commented Aug 29, 2013 at 22:08

2 Answers 2

2

That's not an error. Read the response - it's a filelike object.

br.select_form("login")
br.form['j_username'] = 'xyz'
br.form['j_password'] = 'pass'
pag2 = br.submit()
html = pag2.read()
print html
Sign up to request clarification or add additional context in comments.

3 Comments

@MilchePatern Tempted to PEP8 it. ;)
the page that is coming after submitting is the same page with error.. onclicking the button some javescript code runs.. is mechanize support the javascript in it?
@RATHI Mechanize has no javascript engine. you can often get around javascript by just posting/getting from the url where the javascript would have.
1

This is a submit button. A submit button in HTML is by definition an <input> element of type submit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.