登录盈盈理财

# -*- coding:utf-8 -*-    

from html.parser import HTMLParser
from urllib.parse import urlparse

import urllib
import urllib.request
import http.cookiejar
import string
import re

def getOpener(head):
  cj = http.cookiejar.CookieJar()
  pro = urllib.request.HTTPCookieProcessor(cj)
  opener = urllib.request.build_opener(pro)
  header = []
  for key, value in head.items():
    elem = (key, value)
    header.append(elem)
  opener.addheaders = header
  return opener

hosturl = 'https://licai.yingyinglicai.com/index.htm'
posturl = 'https://licai.yingyinglicai.com/user/loginByPwd.do'
token = ''

header = {
  'Referer':'https://licai.yingyinglicai.com/user/login.htm',
  'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER'
}

opener = getOpener(header)
response = opener.open(posturl)
page = response.read()
if(page):
  page_decode = page.decode('gbk');
  regex = r'.*token"\s+value="(.*?)"/.*'
  reObj = re.compile(regex)
  token = re.search(reObj, page_decode).group(1)

postData = {
            'token' : token,
            'cell' : '用户名',
            'password' : '密码'
           }
pD = urllib.parse.urlencode(postData).encode('gbk')

op = opener.open(posturl, pD)
#print(op.read().decode('gbk'))

op = opener.open(hosturl)
print(op.read().decode('gbk'))

你可能感兴趣的:(登录盈盈理财)