Beispiel #1
0
def requestPubCookieL():
    credentials = getCredentials();
    headers = {
        'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        'upgrade-insecure-requests': "1",
        'user-agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36",
        'content-type': "application/x-www-form-urlencoded",
        'accept-language': "en-US,en;q=0.8,sl;q=0.6",
        'cache-control': "no-cache",
    }

    url = "https://weblogin.washington.edu"
    parser = HiddenFieldParser()
    cookieJar = http.cookiejar.CookieJar()

    page = makeRequest(url, headers)
    parser.feed(page)

    # Add our credentials.
    parser.data["user"] = credentials[0]
    parser.data["pass"] = credentials[1]
    # Encode it into HTTP payload format (in ascii/bytes).
    body = parse.urlencode(parser.data).encode("ascii")

    req = request.Request(url, body, headers)
    response = request.urlopen(req)
    cookieJar.extract_cookies(response, req)

    for x in cookieJar:
        if x.name == "pubcookie_l":
            return (x.name, x.value)
Beispiel #2
0
def requestPubCookieG(url):
    credentials = getCredentials()
    headers = {
        'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        'upgrade-insecure-requests': "1",
        'user-agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36",
        'content-type': "application/x-www-form-urlencoded",
        'accept-language': "en-US,en;q=0.8,sl;q=0.6",
        'cache-control': "no-cache",
    }

    parser = HiddenFieldParser()
    cookieJar = http.cookiejar.CookieJar()
    while 'pubcookie_g' not in parser.data:
        page = makeRequest(url, headers, parser.data)
        # Parse the hidden fields.
        parser.reset()
        parser.feed(page)
        if parser.login:
            # Add our login credentials.
            parser.data['user'] = credentials[0]
            parser.data['pass'] = credentials[1]
        url = parser.relay

    return ("pubcookie_g", parser.data["pubcookie_g"])