我正在玩机械化尝试为我的网站创建蛮力我只是想知道如何检查表单是否已成功提交
至今:
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)