爬虫(12):通过抓取登陆前令牌认证登陆

import urllib
from urllib import request, parse
from http import cookiejar

cookieF = 'cookie1.txt'
cookie = cookiejar.LWPCookieJar()

cookie_handler = urllib.request.HTTPCookieProcessor(cookie)

opener = urllib.request.build_opener(cookie_handler)

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"}

data = {
    'email': '18588403840',
    'icode': '',
    'origURL': 'http://www.renren.com/home',
    'domain': '    renren.com',
    'key_id': '    1',
    'captcha_type': 'web_login',
    'password': '2dbf8c263cbefc9b32113a5a65a7cb23fc8264e9f1f2bc51d402859b473c8704',
    'rkey': '8674c4b1b7f9d56a99bf48984a0591ba',
    'f': 'https%3A%2F%2Fwww.sogou.com%2Flink%3Furl%3DDSOYnZeCC_r-h4h4RsVJtWYvcrgiTSe0'
}
data = urllib.parse.urlencode(data).encode('utf-8')

logurl = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018622138928 '

req = urllib.request.Request(url=logurl, data=data, headers=headers)

response = opener.open(req)

cookie.save(filename=cookieF, ignore_discard=True, ignore_expires=True)

print(response.read().decode('utf-8'))

你可能感兴趣的:(爬虫(12):通过抓取登陆前令牌认证登陆)