html - Python mechanize not recognizing form -
i'm trying login @ this page.
br = mechanize.browser(factory=mechanize.robustfactory()) br.set_cookiejar(cj) current_page = br.open(login_url) soup = beautifulsoup(current_page.get_data()) current_page.set_data(soup.prettify()) br.set_response(current_page) print soup.findall('form') assert br.viewing_html() f in br.forms(): print f.name
but prints none forms though beautifulsoup finding form perfectly. have ideas?
something work:
bs4 import beautifulsoup import mechanize import cookielib br = mechanize.browser() cj = cookielib.lwpcookiejar() br.set_cookiejar(cj) host = 'https://order.papajohns.com/secure/signin/frame.html?destination=http%3a%2f%2forder.papajohns.com%2findex.html%3fsite%3dweb%26dclid%3d%2525n-2543611-4121096-71899047-246709315-0%26esvt%3d336192-gouse339376223%26esvq%3dpapa%2520johns%26esvadt%3d999999-0-3934985-1%26esvcrea%3d41751468573%26esvplace%26esvd%3dc%26esvaid%3d30536%26gclid%3dci2psohqtbwcfrpxogodr0gaag' br.addheaders = [('user-agent', 'firefox')] br.open(host) br.form = list(br.forms())[0] br.form['username'] = username br.form['pwd'] = password submit = br.submit() code = response.read() soup = beautifulsoup(code)
Comments
Post a Comment