Hugh
Hugh

Reputation: 47

Select first input box Mechanize

I'm writing a Python app that will interact with certain websites. I need to select the 1st input box in the website, how do I do this without knowing the name of said input box? I currently have

br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open("http://localhost")  
br.select_form(nr=0)
# ???

br.method = "GET"
response = br.submit()
print response

But I'm stuck on what to do next? I've looked on various webpages but none seem to answer my question

Upvotes: 0

Views: 139

Answers (2)

Nathan Vērzemnieks
Nathan Vērzemnieks

Reputation: 5603

Try:

br.select_form(nr=0)
inputName = br.form.find_control(nr=0).name
br.form[inputName] = value

Upvotes: 1

smallwat3r
smallwat3r

Reputation: 1117

Maybe you should check if Selenium can help?

Upvotes: 0

Related Questions