[Tutor] running a javascript script with python

Benjamin Fishbein bfishbein79 at gmail.com
Thu Nov 1 21:13:08 CET 2012


I'm on a website that produces an error the first time I submit text. The second time I click enter or click on the submit button, the text is submitted and the results that I want are given to me.
The problem is that I want to automate this, but the server treats each submission as the first one...I always get the error. I thought that perhaps if I run the javascript it might work.
Here's the script it has for reentering(it's a standard text entry javascript from what my googlesearch tells me):
<script language='javascript'>function submitenter(myfield,e) {var keycode;if (window.event) {keycode = window.event.keyCode;}else if (e) {keycode = e.which;}else {return true;}if (keycode == 13) {myfield.form.submit();return false;}else {return true;}}</script>
The part of my code that doesn't work is this:

text=opener.open(url,encoded_data).read()

('opener' is an object that has all the cookies and headers put in place)

The text always has the error.

I tried this:

for i in range(10):
	text=opener.open(url,encoded_data).read()
	if 'Error: BB-09-00-05' in text:
		print "Sorry, the error is there."
	else:
		print "Success!!!"
		print text

The output is ten lines of "sorry, the error is there."


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121101/51af9c2e/attachment.html>


More information about the Tutor mailing list