[Tutor] DOMForm

Pete Froslie froslie at gmail.com
Fri Jun 26 23:09:00 CEST 2009

Hi, so I've been using Mechanize as suggested to me through tutor to access
web forms and fill them out.. I've found some success though I wish there to
be more documentation than docstrings.. as I am new to python and not
incredibly experienced with code.

I am able to fill forms and submit them in situations such as a
'search-submit' form on a blog.  *My problem is evident when I approach a
form that appears to be linked to a javascript -- I am unable to
submit*(essentially click on the button).. I assume this is because
python does not
handle javascript.  I am now looking at DOMForm as a solution, but am unsure
as to weather or not this is correct..

An example of the form I would like to access looks like this:

<form name="PXForm" method="post"
<input type="hidden" name="__VIEWSTATE"
value="dDw1MzgxOzs+PgGFOMY4OYGDkEPDYUq1qgpsu4g=" />
<input name="__PXPOSTBACK" id="__PXPOSTBACK" type="hidden" value="1"
/><script language="JavaScript" type="text/javascript"

<SCRIPT LANGUAGE=javascript>
	function resetpxslbp() {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["PXForm"];
		else {
			theform = document.PXForm;
		theform.__PXLBN.value = ('');
		theform.__PXLBV.value = ('');
	function pxslbp(eventTarget, eventArgument) {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
			theform = document.forms["PXForm"];
		else {
			theform = document.PXForm;
		theform.__PXLBN.value = eventTarget;
		theform.__PXLBV.value = eventArgument;

#the is more like the above I'm leaving out before the standard form
entry html such as the following:

td align="Left" class="LabelCell"><span class="PrintSmall">Enter
e-mail address of recipient</span></td>
				<td align="Left" class="Cell"><input name="Email_To" type="text"
maxlength="255" size="40" id="Email_To" class="CustomTextbox" /></td>


The python code I've put together looks like this:

*import ClientForm
import urllib2
request = urllib2.Request("http://www.qinetiq-nacareers.com/qinetiq/jobboard/SendToFriend.aspx?__JobID=*C2B68228BC44075E")
response = urllib2.urlopen(request)
forms = ClientForm.ParseResponse(response, backwards_compat=False)

form = forms[0]
print form

form["Email_To"] = "pfroslie at gmail.com"
form["Email_From"] = "pfroslie at gmail.com"
form["SenderName"] = "Patrick"
form["Comments"] = "this job looks great"

request2 = form.click("Send")

print form
control = form.find_control("Email_To", type="text")
print control.name, control.value, control.type
print request
print request2*

i've tried a few other options, but essentially feel my trouble boils
down to thos issue with java..

*Thank you so much!-- I appologoze if this post is formatted a little
too confusing-- kind of getting use to communicating about pythono..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090626/a25434c5/attachment-0001.htm>

More information about the Tutor mailing list