Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Mechanize input text in form

I'd like to input some text in the text field 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() 
like image 488
Shreedhar Manek Avatar asked Mar 13 '26 08:03

Shreedhar Manek


1 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(). It that is what you want, you can parse the response with Beautiful Soup. soup = BeautifulSoup(br.response().read())

like image 123
ssm Avatar answered Mar 14 '26 20:03

ssm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!