csprajeeth
csprajeeth

Reputation: 237

Creating a custom form for mechanize

I have a form on a website that is not directly selectable (as it is embedded in a javascript). So selecting it via mechanize browser object is not possible. What i want to do is to create a form just like that one and submit it using the browser object.

The form is

<form method="POST" action="Action.php?action=338&n=66&t=mine">
<input id="Mine66" type="hidden" value="22" name="duree">
<button class="boutonsGeneral" value="submit" type="submit" name="travail">
<span class="infoBoutonsGeneral" title="">
Work
<span id="dureeMine66" class="boutonsGeneral_duree boutonsGeneral_dureePlus">22 hours</span>
</button>
</form>

I used firebug and here is the info. The URL posted to is http://www.renaissancekingdoms.com/Action.php?action=338&n=66&t=mine

Parameters

duree 22

travail submit

Request Headers From Upload Stream

Content-Length: 23

Content-Type: application/x-www-form-urlencoded

What i have done so far is that i managed to log into the site and did the following

form = mechanize.HTMLForm('http://www.renaissancekingdoms.com/Action.php?action=338&n=66&t=mine', method='POST')

form.new_control('duree', 'hidden', {
    'id' : 'Mine66',
    'value' : '22'})
form.fixup()
br.form = form
br.submit()

But this doesn't seem to work. Any ideas where i am going wrong?

Upvotes: 0

Views: 388

Answers (1)

nnaelle
nnaelle

Reputation: 902

have you tried going directly to the link passing the post data as a parameter? like this :

r = opener.open('http://example.com/', data)

where data is the post data as a dictionnary

Upvotes: 1

Related Questions