Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Completing HTML forms with Python - help
New Posts  All Forums:Forum Nav:

Completing HTML forms with Python - help

post #1 of 2
Thread Starter 
I'm trying to complete a HTML form (see further down), but can't get all of the parameters to take the values I'm passing. I can change the values for the 'dname', 'x' and 'y' elements, but not for the 'r1', 'r2', 'r3', 'r4' elements.

Only pattern I can see is that the parameters I can update are in the second table, whilst those I can't are in the first table. Also, the values r1,r2,r3,r4 are used as class values as well as name values - I have no idea if this is an issue at all.

The code I'm using is essentially this:
Code:
cookieJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))

opener.addheaders = [('User-agent', "Mozilla/5.0")]

amount = urllib.urlencode({'r1':111,'r2':222,'r3':333,'r4':444,'dname':'A'})

market_url = "http://s6.travian.com/build.php?id=33"
request = urllib2.Request(market_url, amount)
market_page = opener.open(request).read()
print market_page
I print the page to check which elements are having their values updated, and which aren't.

Below is the HTML form I'm trying to complete:
Code:
<form method="POST" name="snd" action="build.php">
<input type="hidden" name="id" value="33">
<table id="send_select" class="send_res" cellpadding="1" cellspacing="1"><tr>
<td class="ico">
<a href="#" onClick="upd_res(1,1); return false;"><img class="r1" src="img/x.gif" alt="Lumber" title="Lumber" /></a>
</td>
<td class="nam">
Lumber:
</td>
<td class="val">
<input class="text" type="text" name="r1" id="r1" value="" maxlength="5" onKeyUp="upd_res(1)" tabindex="1">

</td>
<td class="max">
<a href="#" onMouseUp="add_res(1);" onClick="return false;">(750)</a>
</td>
</tr><tr>
<td class="ico">
<a href="#" onClick="upd_res(2,1); return false;"><img class="r2" src="img/x.gif" alt="Clay" title="Clay" /></a>
</td>

<td class="nam">
Clay:
</td>
<td class="val">
<input class="text" type="text" name="r2" id="r2" value="" maxlength="5" onKeyUp="upd_res(2)" tabindex="2">
</td>
<td class="max">
<a href="#" onMouseUp="add_res(2);" onClick="return false;">(750)</a>
</td>

</tr><tr>
<td class="ico">
<a href="#" onClick="upd_res(3,1); return false;"><img class="r3" src="img/x.gif" alt="Iron" title="Iron" /></a>
</td>
<td class="nam">
Iron:
</td>
<td class="val">
<input class="text" type="text" name="r3" id="r3" value="" maxlength="5" onKeyUp="upd_res(3)" tabindex="3">

</td>
<td class="max">
<a href="#" onMouseUp="add_res(3);" onClick="return false;">(750)</a>
</td>
</tr><tr>
<td class="ico">
<a href="#" onClick="upd_res(4,1); return false;"><img class="r4" src="img/x.gif" alt="Crop" title="Crop" /></a>
</td>

<td class="nam">
Crop:
</td>
<td class="val">
<input class="text" type="text" name="r4" id="r4" value="" maxlength="5" onKeyUp="upd_res(4)" tabindex="4">
</td>
<td class="max">
<a href="#" onMouseUp="add_res(4);" onClick="return false;">(750)</a>
</td>

</tr></table>

<table id="target_select" class="res_target" cellpadding="1" cellspacing="1">
<tr>
<td class="mer">Merchants 19/19</td>
</tr>
<tr>
<td class="vil">
<span>Village:</span>

<input class="text" type="text" name="dname" value="" maxlength="20" tabindex="5">
</td>
<tr>
<td class="or">or</td>
</tr>
<tr>
<td class="coo">
<span>X:</span><input class="text" type="text" name="x" value="" maxlength="4" tabindex="6">

<span>Y:</span><input class="text" type="text" name="y" value="" maxlength="4" tabindex="7">
</td>
</tr>
</table>
<div class="clear"></div><p><input type="image" value="ok" name="s1" id="btn_ok" class="dynamic_img" src="img/x.gif" tabindex="8" alt="OK" /></form></p>

Edited by thealmightyone - 6/10/10 at 12:49pm
post #2 of 2
Thread Starter 
Dirty bump, as I've pretty much re-written the original post.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Completing HTML forms with Python - help