1
幫助我玩機械化 試圖使蠻力,我的網站 我只是想知道如何檢查,如果表單已成功提交Python中,需要在製作「蠻力」使用機械化
到目前爲止:
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)