登录北京住房公积金,使用已注册过账号

import requests,os
from queue import Queue
from hashlib import md5
import base64
import json,time
from retrying import retry
import warnings

# 取消warning提示
warnings.filterwarnings("ignore")
s = requests.session()
s.verify = False
s.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', })
# q_cookis = Queue()


def check_text(text):
'''
检查是否充重试
:param text:网站源码
:return: 不存在源码中
'''
return text is not True


def check_str(strs):
'''
md5加密
:param 密码
:return: md5加密后的32位
'''
m = md5()
m.update(strs.encode(encoding='utf-8'))
return m.hexdigest()


@retry(retry_on_result=check_text, stop_max_attempt_number=3, wait_fixed=1000)
def log_in(user,pasw):
img_url = 'https://grwsyw.bjgjj.gov.cn/ish/ranCode.jsp?_='+str(int(time.time()*1000))
s.get('https://grwsyw.bjgjj.gov.cn/ish/')
img = s.get(url=img_url)
dic_ = json.loads(img.text)
url = dic_['image'].replace('data:image/jpeg;base64,','')
code_key = dic_['key']
f = open('code.jpg','wb')
f.write(base64.b64decode(url))
f.close()
os.system('code.jpg'.replace('/','\'))
codes = input('验证码:')
data = {
'logintype': 'person',
'yzmkey': code_key,
'dlmm': check_str(pasw),
'zdyyhm': user,
'dlmmMD5': pasw,
'yzm': codes,
'xyjmdzd': ''
}
log_in_url = 'https://grwsyw.bjgjj.gov.cn/ish/login'
s.post(url=log_in_url,data=data)
myself_url = 'https://grwsyw.bjgjj.gov.cn/ish/home?_r=45362b79abc8e32c6652bc7ce446'
check_text = s.get(myself_url)
if '个人信息' in check_text.text:
print('login Sucesses')
# cookie = '; '.join(['='.join(item) for item in check_text.cookies.items()])
# q_cookis.put(cookie)
return True
else:
return False



log_in(user,pasw)
原文地址:https://www.cnblogs.com/zhangheng1/p/9105514.html