Python_2_Examples_and_Notes/36_web_mechanize_forms_clic...

33 lines
636 B
Python
Raw Permalink Normal View History

2017-10-11 20:07:24 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
import mechanize
# Note: mechanize takes care of cookies.
br=mechanize.Browser()
br.open('http://student.securitytube.net/login/index.php')
for form in br.forms():
print form
br.select_form(nr=0)
br.form['username'] = 'demo-user'
br.form['password'] = 'demouser1]M' # It won't work ;)
br.submit()
print br.response().read
for link in br.links():
print link.url + ' + ' + link.text
# It's different url now, just for example:
#new_link = br.click_link(text='moodle[IMG]Change Password')
#br.open(new_link)
#print br.response().read()
#for form in br.forms():
# print form