I am trying to use the mechanize module to automate a task on the web. I am able to get the first form to submit correctly. After I submit the first form I would like to take the data from the second website(or form) I am taken to(after I enter my first and last name) and enter in more information. Can someone tell me how to take information from second form and submit data into that form? Thanks.

import mechanize
import re

br=mechanize.Browser()
br.open('www.example.com')
br.select_form(nr=1) 
br['firstName']='firstname' 
br['lastName']='lastname' 
br.submit() #How can I open up the website I am taken to after I submit my first and last name? 

I figured out my last question. I just used geturl() function to get the url of the new webpage that was opened up by submitting the previous form. In my second web page I have 3 different submit buttons. How do I select the one that I want.

import mechanize

br=mechanize.Browser()
br.set_handle_robots(False)
br.open('http://www.example.com')
br.select_form(nr=1) #check yoursite forms to match the correct number
br['firstName']='firstname' #use the proper input type=text name
br['lastName']='lastname' #use the proper input type=password name
response1 =br.submit()
checkin_URL = response1.geturl()
print checkin_URL

br.open(checkin_URL)
br.select_form(nr=2) #check yoursite forms to match the correct number
response2 = br.submit()
content = response2.read()
final_checkin_URL = response2.geturl()
print final_checkin_URL


        <input type="submit" class="buttons_submitButton_white" id="cancelButton" value="Cancel"
               title="Cancel" name="cancel"/>


            <input type="submit" class="buttons_submitButton "  id="printDocumentsButton" value="Check In"
                   title="Check In" name="printDocuments"/>

I would like to select the "Check In" submit button. I can't seem to get my program to work correctly. What is wrong??

I figured out my issue. It had to do with the form that I was selecting. The submit buttons I was trying to access were actually on form 3, not form 2.

I figured out my issue. It had to do with the form that I was selecting

I would advise you if the problem had been solved, or you yourself resolved the isue to mark the thread as solved, in order for others who seek problems to solve not to bother opening this thread.

The submit buttons I was trying to access were actually on form 3, not form 2.

Common errors may quickly be idenfied by debugging the program. In your case was a minor misspelled function.

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.