登录+获取驾驶本违章信息

 

#coding:utf-8
import os
import re
import ydm
import time
import requests





class Driver:
s = requests.session()
provice = ''

def __init__(self,number,password):
self.number = number
self.password = password


def login(self,nums=3,times=60):
head = {
'User-Agent': "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5"
}
capcha_url = 'https://gab.122.gov.cn/sso/captcha?nocache=' + str(int(time.time() * 1000))
img = self.s.get(capcha_url)
with open('capcha.jpg', 'wb')as f:
f.write(img.content)

'''
云打码验证图片
username = '云打码账号'
password = '密码'
appid = 4359
appkey = '0715011dad66b60956de51723d5509c2'
filename = 'capcha.jpg'
codetype = 1004
timeout = 60
if (username == 'username'):
print('请设置好相关参数再测试')
else:
yundama = ydm.YDMHttp(username, password, appid, appkey)
balance = yundama.balance()
print('balance: %s' % balance)
# 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果
cid, result = yundama.decode(filename, codetype, timeout)
print('验证码为:',result)
code = result
'''
os.system('capcha.jpg')
code = input('验证码::::::')
try:
post_data = {
'appid': '000000',
'usertype': '1',
'username': self.number,
'password': self.password,
'captcha': str(code)
}
dbs = self.s.post('https://gab.122.gov.cn/sso/login/db', data=post_data, allow_redirects=False, headers=head,timeout=times)
time.sleep(1)
log_1 = self.s.get(dbs.headers['Location'], headers=head, allow_redirects=False,timeout=times)
num = re.search('.cn(.*?)/m/.*?', log_1.headers['Location']).group(1)
print(log_1.headers['Location'])
# print(num)
print(log_1.headers['Location'].replace(num, ''))
log_2 = self.s.get(log_1.headers['Location'].replace(num, ''), allow_redirects=False, headers=head,timeout=times)
log_s = self.s.get(log_2.headers['Location'], allow_redirects=False, headers=head,timeout=times)
log_ss = self.s.get(log_s.headers['Location'], allow_redirects=False, headers=head,timeout=times)
ast = self.s.get(log_ss.headers['Location'], allow_redirects=False, headers=head,timeout=times)
log_t1 = self.s.get(ast.headers['Location'], allow_redirects=False, headers=head,timeout=times)
log_t2 = self.s.get(log_t1.headers['Location'], allow_redirects=False, headers=head,timeout=times)
jes = self.s.get(log_t2.headers['Location'], allow_redirects=False, headers=head,timeout=times)
# global provice
self.provice = re.search('http://(\w+).122.gov.cn.*?', jes.url).group(1)
print(jes.text)
print(self.provice)
except Exception as e:
print(e)
print('5秒后重试')
time.sleep(5)
if nums > 0:
print('还有', nums, '次机会....')
return self.login(nums - 1)
else:
exit()




d = Driver('驾驶本编号','密码')
d.login()

 

posted on 2018-03-26 11:11  一止小菜鸟  阅读(768)  评论(0编辑  收藏  举报