I’m playing with mechanize
Trying to make a brute force for MY website
I’m just wondering how to check if the form was submitted successfully
so far:
import mechanize
import cookielib
import urllib
import HTMLParser
import re
# Browser
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
url = 'http://mywebsite'
pattern = '''Welcome (.*)'''
passwords = ('lol','lol1','correctPassword')
r = br.open(url)
try:
br.select_form(nr=0)
br.form['username']='Matt'
found = False
i=0
while not found:
br.form['password']=passwords[i]
# here I want to check if br.submit() was successful
# than break the loop (or simply make found = True)
# if not, increment i
br.submit()
except:
print "Not Good"
html = br.response().read()
message = re.findall(pattern, html)
parser = HTMLParser.HTMLParser()
print parser.unescape(message)
I had a similar question. And there is no documentation on it.
If not already known. I suggest you use br.click()
I checked the error by looking at error elements on the webpage.
Something like this
Hope this helps