Python and mechanize login script

前端 未结 3 1757
再見小時候
再見小時候 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条回答
  •  庸人自扰
    2021-02-14 19:41

    # User credentials
    br.form['id']  = myId
    br.form['PIN'] = myPin
    

    I believe this is the problem line.

    Try changing it to

    br['id'] = myId
    br['PIN'] = myPin
    

    I'm also pretty sure that you don't need br.form.action = 'https://itapp.wcu.edu/BanAuthRedirector/Default.aspx' because you have already selected the form so just calling submit should work, but I could be wrong.

    Additionally, I have done a similar task just using urllib and urllib2, so if this doesn't work I will post that code.

    Edit: here is the the technique that I used with urllib and urllib2:

    import urllib2, urllib
    
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
    urllib2.install_opener(opener)
    encoded = urllib.urlencode({"PIN":my_pin, "id":my_id})
    f = opener.open('http://www.wcu.edu/11407.asp', encoded)
    data = f.read()
    f.close()
    

    Edit 2:

    >>> b = mechanize.Browser(factory=mechanize.RobustFactory())
    >>> b.open('http://www.wcu.edu/11407.asp')
    >>
    >>> b.select_form(nr=2)
    >>> b.form
    
    >>> b.form.attrs
    {'action': 'https://itapp.wcu.edu/BanAuthRedirector/Default.aspx', 'method': 'post'}
    

    This could be your problem? Not sure.

    Edit 3:

    Used an html inspector, I think there's a decent chance you need to set 'wcuirs_uir' to 'https://cf.wcu.edu/busafrs/catcard/idsearch.cfm'. I'm 95% sure that will work.

提交回复
热议问题