import urllib2 import urllib import cookielib # import re from lxml import html USERNAME = "xxxUSERxxx" PASSWORD = "yyyPASSWDyyy" LOGIN_URL = "https://www.geocaching.com/account/login?ReturnUrl=%2Fplay%2Fsearch" URL = "https://www.geocaching.com/seek" def main(): cookie = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) respon = opener.open(LOGIN_URL).read() tree = html.fromstring(respon) authenticity_token = list(set(tree.xpath("//input[@name='__RequestVerificationToken']/@value")))[0] print authenticity_token # Create payload payload = { "Username": USERNAME, "Password": PASSWORD, "__RequestVerificationToken": authenticity_token } # Perform login result = opener.open(LOGIN_URL, urllib.urlencode(payload)) result.geturl() info = result.read() print info if __name__ == '__main__': main()