0

I am trying to detect whether logging into a web form creates a redirection or not. Right now this process is fairly slow:

import urllib, urllib2

def redirection_occurs(user, password, login_page_url ):

    login_data = urllib.urlencode({
        'username':user,
        'password':password
    })

    data = urllib2.urlopen( login_page_url, login_data )

    # Returns true if redirection occurs
    return data.geturl() != login_page_url

What makes the whole thing slow is the call to urllib2.urlopen( login_page_url, login_data ), is there a way around this? I simply want to detect whether or not a redirection has occurred after a login.

will.fiset
  • 1,524
  • 1
  • 19
  • 29

1 Answers1

0

this seems to be largely answered here although not a perfect repeat question.

nevertheless, use a heads request

in python requests its

requests.head(url, **kwargs)

instead of

requests.request(method, url, **kwargs)

Using the urllib2 library use the answers from this SO question

Community
  • 1
  • 1
Gabe Rainbow
  • 3,658
  • 4
  • 32
  • 42