0

I have been working on this problem for a good 6 hours and I cannot for the life of me figure out why the form is not sending properly

br = mechanize.Browser()

    br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36')]
    #Makes it appear to be chrome
    cj = cookielib.LWPCookieJar()
    br.set_cookiejar(cj)


     br.set_handle_equiv(True)
     br.set_handle_gzip(True)
     br.set_handle_redirect(True)
     br.set_handle_referer(True)
    br.set_handle_robots(False)

    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

    br.open("website")
    linkfollow = br.follow_link()
    br.select_form("aspnetForm")
    br.form.set_all_readonly(False)
    #Select form and set all readonly to False

    control = br.form.find_control(name="namehere")
    control.value = str(zipcode)

    #Finds the control that toggles the zip codes
    #this will iterate through a list eventually

    print br.geturl()
    response = br.submit(name="button_i_want_to_click_on")

    print br.geturl()



    #IT ALL WORKS UP TO HERE< FORM SUBMITS PROPERLY AND LOADS NEXT HTTP



    br.select_form("aspnetForm")
    br.form.set_all_readonly(False)

    br.form["Radio group that i selected (I know this is correct)"] = ['correctValue']
    br.form["Other Radio Group Thats selected"] = ['correctValue']


    new_response = br.submit(name="Next Submit Button I want to click on")

    print new_response.geturl()

I had to change the values and such because this is work related, but I fill in the radio buttons, and when I check if the elements have been selected it works fine. But when I submit the form it does not bring me to the next page in the sequence like it does when I do the exact same thing in the google chrome browser.

Are there things in JavaScript at work behind the scenes not allowing me to submit this form? Is there a better tool I should be using for web navigation such as this.

Can somebody help? This is driving me insane.

Matt
  • 101
  • 1
  • 1
  • 4
  • Since you are using Chrome already, open the Developer Tools and inspect the request that is actually being sent when you are successful in the browser. Pay attention to the post/get data in case javascript is injecting anything. Also, make sure you are using a CookieJar as it might be something as simple as missing a Cookie that is set when you hit the page. – sberry Sep 10 '14 at 22:19
  • Thanks, ill try this, but I'm not exactly sure on how to incorporate the infomration I'm gettin from these cookie into cookielib. So for example it has name, content, path, domain, etc. How would I go about adding cookies into the jar and presenting those specifically when I reach the Request I want? – Matt Sep 10 '14 at 23:24

0 Answers0