Python and mechanize login script

前端 未结 3 1763
再見小時候
再見小時候 2021-02-14 19:19

Hi fellow programmers!

I am trying to write a script to login into my universities \"food balance\" page using python and the mechanize module...

This is the pag

3条回答
  •  Happy的楠姐
    2021-02-14 19:47

    I suggest the following library: http://docs.python-requests.org/en/latest/

    It is a nice and easy library. It has a good documentation. I have used this library to do different kind of scripting, just like the one you are doing.

    You need to do something like this:

    import requests 
    
    s = requests.Session()
    url = 'https://itapp.wcu.edu/BanAuthRedirector/Default.aspx'                    
    myId = 'xxxxxxxx'                                                               
    myPin = 'xxxxxxxx'  
    headers = {'User-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
               'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
               'Accept-Encoding': 'gzip,deflate,sdch',                  
               'Accept-Language': 'en-US,en;q=0.8',                     
               'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3'}
    data = {'id':myId,                                                          
            'PIN':myPin,                                                        
            'submit':'Request Access',                                          
            'wcuirs_uri':'https://cf.wcu.edu/busafrs/catcard/idsearch.cfm'} 
    response = s.post(url, headers = headers, data=date)
    
    if response.status_code == 200: #Maybe add another constraint to be sure we are logged in
        #Now do any call you want
        response = s.get(another_url)
        print response.text
    

    You can get more info here

提交回复
热议问题