登录北京社保网站
登录北京社保网站(失败重试3次):
@deco
def retry_if_result_none(result):
logger.info('登录状态%s' % result)
return '用户,欢迎您!' not in result
s = requests.session()
q_cookie = Queue()
class Longin:
def __init__(self,username,password):
self.username = username
self.password = password
print('1:城镇职工')
print('2:城乡居民')
@retry(retry_on_result=retry_if_result_none,stop_max_attempt_number=3, wait_fixed=1000)
def logins(self):
s.headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
}
key = input('请选择社保类型:')
if key == 1:
s.get('http://www.bjrbj.gov.cn/csibiz/indinfo/login.jsp')
elif key == 2:
s.get('http://www.bjrbj.gov.cn/csibiz/urbmi/login.jsp')
with open('picture/q_img.png','wb')as f:
f.write(s.get('http://www.bjrbj.gov.cn/csibiz/indinfo/validationCodeServlet.do').content)
os.system('picture/q_img.png'.replace('/', '\\'))
code = input('请输入图片验证码')
send_code_url = 'http://www.bjrbj.gov.cn/csibiz/indinfo/passwordSetAction!getTelSafeCode'
datas = {
'idCode': self.username,
'logPass': self.password,
'safeCode': code}
s.post(send_code_url, data=datas)
send_code = input('短信验证码:')
log_data = {
'type': '1',
'flag': '3',
'j_username': self.username,
'j_password': self.password,
'safecode': code,
'i_phone': send_code,
'x': '52',
'y': '12'}
s.post('http://www.bjrbj.gov.cn/csibiz/indinfo/login_check',data=log_data)
s.get('http://www.bjrbj.gov.cn/csibiz/indinfo/index2.jsp')
s.get('http://www.bjrbj.gov.cn/csibiz/indinfo/index.jsp')
t = s.get('http://www.bjrbj.gov.cn/csibiz/indinfo/top_ind.jsp')
cookie = '; '.join(['='.join(item) for item in t.cookies.items()])
q_cookie.put(cookie)
return t.text
if __name__ == '__main__':
user = input('输入账号:')
passw = input('输入密码:')
l = Longin(user,passw)
l.logins()