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.<br>
<br>I am able to fill forms and submit them in situations such as a 'search-submit' form on a blog. <b>My problem is evident when I approach a form that appears to be linked to a javascript -- I am unable to submit</b> (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..<br>
<br>An example of the form I would like to access looks like this:<br><b>*********************************************************************************************************</b><br><pre id="line965"><<span class="start-tag">form</span><span class="attribute-name"> name</span>=<span class="attribute-value">"PXForm" </span><span class="attribute-name">method</span>=<span class="attribute-value">"post" </span><span class="attribute-name">action</span>=<span class="attribute-value">"SendToFriend.aspx?__JobID=*C2B68228BC44075E&__SVRTRID=B6F5E507-AACA-416D-A03C-1573EA327D41" </span><span class="attribute-name">id</span>=<span class="attribute-value">"PXForm"</span>><br>
<<span class="start-tag">input</span><span class="attribute-name"> type</span>=<span class="attribute-value">"hidden" </span><span class="attribute-name">name</span>=<span class="attribute-value">"__VIEWSTATE" </span><span class="attribute-name">value</span>=<span class="attribute-value">"dDw1MzgxOzs+PgGFOMY4OYGDkEPDYUq1qgpsu4g=" </span><span class="error"><span class="attribute-name">/</span></span>><br>
<<span class="start-tag">input</span><span class="attribute-name"> name</span>=<span class="attribute-value">"__PXPOSTBACK" </span><span class="attribute-name">id</span>=<span class="attribute-value">"__PXPOSTBACK" </span><span class="attribute-name">type</span>=<span class="attribute-value">"hidden" </span><span class="attribute-name">value</span>=<span class="attribute-value">"1" </span><span class="error"><span class="attribute-name">/</span></span>><<span class="start-tag">script</span><span class="attribute-name"> language</span>=<span class="attribute-value">"JavaScript" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript" </span><span class="attribute-name">src</span>=<span class="attribute-value">"../UI/GT/hmscore.js"</span>></<span class="end-tag">script</span>><br>
</pre><pre id="line980"><<span class="start-tag">SCRIPT</span><span class="attribute-name"> LANGUAGE</span>=<span class="attribute-value">javascript</span>><br><!--<br>        function resetpxslbp() {<br>                var theform;<br>
                if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {<br>                        theform = document.forms["PXForm"];<br>                }<br>                else {<br>                        theform = document.PXForm;<br>                }<br>                theform.__PXLBN.value = ('');<br>
                theform.__PXLBV.value = ('');<br>        }<br>        function pxslbp(eventTarget, eventArgument) {<br>                var theform;<br>                if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {<br>                        theform = document.forms["PXForm"];<br>
                }<br>                else {<br>                        theform = document.PXForm;<br>                }<br>                theform.__PXLBN.value = eventTarget;<br>                theform.__PXLBV.value = eventArgument;<br>                theform.submit();<br>        }<br>//--><br></<span class="end-tag">SCRIPT</span>><br>
<b>*********************************************************************************************************</b><br><br>#the is more like the above I'm leaving out before the standard form entry html such as the following:<br>
<br><span class="start-tag">td</span><span class="attribute-name"> align</span>=<span class="attribute-value">"Left" </span><span class="attribute-name">class</span>=<span class="attribute-value">"LabelCell"</span>><<span class="start-tag">span</span><span class="attribute-name"> class</span>=<span class="attribute-value">"PrintSmall"</span>>Enter e-mail address of recipient</<span class="end-tag">span</span>></<span class="end-tag">td</span>><br>
                                <<span class="start-tag">td</span><span class="attribute-name"> align</span>=<span class="attribute-value">"Left" </span><span class="attribute-name">class</span>=<span class="attribute-value">"Cell"</span>><<span class="start-tag">input</span><span class="attribute-name"> name</span>=<span class="attribute-value">"Email_To" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text" </span><span class="attribute-name">maxlength</span>=<span class="attribute-value">"255" </span><span class="attribute-name">size</span>=<span class="attribute-value">"40" </span><span class="attribute-name">id</span>=<span class="attribute-value">"Email_To" </span><span class="attribute-name">class</span>=<span class="attribute-value">"CustomTextbox" </span><span class="error"><span class="attribute-name">/</span></span>></<span class="end-tag">td</span>><br>
<br></pre><br><pre id="line980"><b>*********************************************************************************************************<br><br><br>The python code I've put together looks like this:<br><br></b>import ClientForm<br>
import urllib2<br>request = urllib2.Request("<a href="http://www.qinetiq-nacareers.com/qinetiq/jobboard/SendToFriend.aspx?__JobID=*C2B68228BC44075E">http://www.qinetiq-nacareers.com/qinetiq/jobboard/SendToFriend.aspx?__JobID=*C2B68228BC44075E</a>")<br>
response = urllib2.urlopen(request)<br>forms = ClientForm.ParseResponse(response, backwards_compat=False)<br>response.close()<br><br>form = forms[0]<br>print form <br><br>form["Email_To"] = "<a href="mailto:pfroslie@gmail.com">pfroslie@gmail.com</a>"<br>
form["Email_From"] = "<a href="mailto:pfroslie@gmail.com">pfroslie@gmail.com</a>"<br>form["SenderName"] = "Patrick"<br>form["Comments"] = "this job looks great"<br>
<br>request2 = form.click("Send") <br><br>print form<br>control = form.find_control("Email_To", type="text")<br>print <a href="http://control.name">control.name</a>, control.value, control.type<br>
print request<br>print request2<b><br><br><br>i've tried a few other options, but essentially feel my trouble boils down to thos issue with java..<br><br></b>Thank you so much!-- I appologoze if this post is formatted a little too confusing-- kind of getting use to communicating about pythono..<br>
<b><br></b></pre>
<br>