简体   繁体   中英

Python mechanize - submit form response

I have this code:

import mechanize
def register():
            br = mechanize.Browser()
            br.set_handle_robots(False)
            br.open("http://somtehing.com/form2/index.php")
            br.select_form(nr=0)
            br.form["email"] = "stone@klikni.com"
            br.form["name"] = "Jan"
            br.form["nickname"] = "Vrsrly"
            br.form["postnum"] = "41182"
            br.form["age"] = "52"
            br.form["sex"] = ["man"]
            br.form["tel"] = "+420723545054"
            br.find_control("rules").items[0].selected = True
            res = br.submit()
            content = res.read()
            with open("mechanize_results.html", "w") as f:
                f.write(content)

but when i look on the mechanize_results.html website, it is just a filled form, checkbox checked, but i do not know if it was sent. When I did it manually, it redirected me to a page where "Registered successfully" was written. And I am not getting this response with mechanize. Any ideas how to solve it?

I have just solved a similar problem in witch the form.submit seemed to have No effect

datat = {'username': 'lnIqd6Et','password':'4BafqzIm8sLgWxdvw9Cb'}
#Encode the parameters
data = urllib.urlencode(datat)
#Submit the form (POST request).
print "POST"
browser.open(post_url,data)
print "POSTED"
print browser.open(url_to_get).read()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM