kiddo39 0 Junior Poster in Training

I'm trying to auto send a form submission to a website but it isn't working. I've done this before and it worked but for some reason, using the same basic code, it doesn't seem to submit it. I'm using urllib & urllib2 to open the page and re to parse the info. On the page is a text entry field and a 'submit' button. I've compared the source code of both pages and they appear the same as far as the submission goes. Anything else I can try? I don't want to bother with Beautiful Soup right now because I'm very close with what I have. On the page is:
Answer:
'submit button'

What I've used:

import urllib2
import urllib
import re

url='http://website.here'
strSession='cookie.info.here'
dicHeaders={'COOKIE':strSession}
req=urllib2.Request(url, None, dicHeaders)
f=urllib2.urlopen(req)
strContext=f.read()
out=open("data.txt","w")
out.write(strContext)
out.close()
infile=open("data.txt","r")
      
*re code here*

        answer=10 # answer varies
        print answer
        password=urllib.urlencode({'solution':answer})
        req2=urllib2.Request(url,password,dicHeaders)
        f2=urllib2.urlopen(req2)
        print f2.read()

If I test it like this on the previous page that it worked on, I get the response that says "Sorry, your answer is wrong" which is fine because I know it submitted the answer but on the current page (which is very similar) it doesn't seem to submit it.
Here are the form actions of both pages for comparison. The first is the one that previously worked, the 2nd the new one I'm trying.

********************************************************************************************
<form name="submitform" action="/website.here" method="post"><br />
Answer:
<input size="50" name="solution"><br /><br />
<div style="text-align:center">
<input name ="submitbutton" type="submit" value="submit (remaining time: 3 seconds)">
</div>
</form>
*********************************************************************************************
<form name="submitform" action="/website.here" method="POST"><br />
Answer: <br />
<input size="75" name="solution"><br /><br />
<div style="text-align:center">
<input name ="submitbutton" type="submit" value="Submit (remaining time: 5 seconds)">
</div>

</form>
*********************************************************************************************

Is there another way for me to get this answer to send?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.