3

I would like to fill in and submit a form on a web page using python. The form I want to interact with has several drop down boxes which are filled using JavaScript. I have looked at the mechanize library but it doesn't handle JavaScript. Can you suggest an alternate library/method for interacting with the form?

Cheers,

Pete

2
  • how does the javascript populate them? Does it perform a request for json or xml and populate them from that or does it make them up on the spot? Where do the come from? When I've needed to do this stuff, I just perform the same request as the javascript and parse the response to get the choices. Commented Nov 27, 2010 at 23:39
  • As far as I can tell the form is populated from a JavaScript Array which is available in the page's source code. I have no idea how this array gets populated. The form has a "date" drop down which, when changed, changes the values of another drop down. Commented Nov 27, 2010 at 23:48

2 Answers 2

3
  1. Selenium RC or Windmill (http://www.getwindmill.com/)

  2. Examine the form's returned GET or POST values; use urllib2 to submit synthesized requests directly.

Sign up to request clarification or add additional context in comments.

Comments

0

The form effectively sends information back to the server (or maybe somewhere else) after you press the submit button.

I don't know how you would directly interact with the form, but you could just send the information back to the server in the same way as submitting the form would (without actually submitting it or physically pressing on things).

So for example some forms put the parameters specified in the form (and their values) at the end of the url in the HTTP request once submitting the form. Others put the parameters in the body of the HTTP request. In PHP i know that PHP automatically takes these parameters out for you (into a global array).

In this case you would simply put your own version of the parameters (names/values) in the HTTP request, by looking a what names/values there are in the forms source code.

Although the form may send its information to the server using javascript...

Sorry if that made no sense.

1 Comment

it doesn't matter if the the form is submitted via javascript so long as it does it using either a 'GET' or 'POST' request.

Your Answer

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