使用python登录尝试

时间:2017-07-30 16:02:07

标签: python html login mechanize

我如何知道登录是否有效?我知道req.read返回HTML页面,我是否必须比较HTML页面或什么?

以下是代码:

import urllib2
import cookielib
import urllib
import requests
import mechanize
from mechanize._opener import urlopen
from mechanize._form import ParseResponse
from Tkconstants import BROWSE


EMAIL = raw_input('Inserisci la tua mail: ')
PASSWORD = raw_input('Inserisci la password: ')

URL = 'https://' +raw_input('Inserici il sito:')

def main():
    browser = mechanize.Browser()
    browser.set_handle_robots(False)
    browser.open(URL +'/login.php?')
    browser.select_form(nr = 0)
    browser.form['email'] = EMAIL
    browser.form['pass'] = PASSWORD
    req=browser.submit()
    print req.read()

if __name__=='__main__':
    main()

0 个答案:

没有答案