Python - Mechanize Input Text in Form

I would like to enter text into a text box of a form. This is my current code. What should I do next?

import re
from mechanize import Browser

br = Browser()
br.open("xyz.com")
formcount=0
for frm in br.forms():  
if str(frm.attrs["id"])=="xyz":
break
formcount=formcount+1
br.select_form(nr=formcount)

## What should I code here to input text into the form?

response = br.submit() 

      

+3


source to share


2 answers


br.form['id'] = 'ss-form' # This does the input
br.submit() # This will submit the form
print br.response().read() # This will read the new page returned

      



try a print br.response().read()

. This is what you want, you can parse the answer with Beautiful Soup.soup = BeautifulSoup(br.response().read())

+2


source


If the form is unnamed, you can use:

br.select_form(nr=0)

      



This will select the first view ("0").

0


source







All Articles