赞
踩
语言:python2.7
第三方包:request,io, pytesseract, PIL, json
from io import BytesIO
import pytesseract
from PIL import Image
import json
username='*********' #登录者的账号
password='000'
num=283 #填写想要的位置
select_day='2017-08-06' #选择自习的时间
select_area='7' #选择自习室
space_area=1688+num # 抢座位的开始座位 第一自习室B 1993-2032
s=requests.session() #建立会话
login_url='http://***.*.***/Home/Web/index'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/59.0.3071.115 Safari/537.36'}
r=s.get(login_url,headers=headers)
login_url_1='http://***.*.***/api.php/areas/1'
r=s.get(login_url_1,headers=headers)
while True :
img_url='http://***.*.***/api.php/check'
r=s.get(img_url) #验证码
i = Image.open(BytesIO(r.content))
vcode = pytesseract.image_to_string(i,config ='-psm 6 digit')
login_url_2='http://***.*.***/api.php/login' ##登录
login_data={
'username':username,
'password':password,
'verify':vcode
}
r=s.post(login_url_2,headers=headers,data=login_data)
r_json=json.loads(r.text)
if r_json['msg']==u'登陆成功':
print ('%s' % r_json['data']['list']['name'])
break
access_token=r_json['data']['_hash_']['access_token'] #拿到登录的token
userid=r_json['data']['_hash_']['userid'] #拿到登录的token
url_gd='http://***.*.***/api.php/space_time_buckets' #选择自习室
payload = {'day': select_day ,'area': select_area }
r = s.get(url_gd, params=payload) #传递url
rr_json=json.loads(r.text) #获取可预约的时间段
print ('%s' % rr_json['msg'])
segment=rr_json['data']['list'][0]['bookTimeId'] # 获取segment
day=rr_json['data']['list'][0]['day'] # 获取day
startTime=rr_json['data']['list'][0]['startTime'] # 获取startTime
endTime=rr_json['data']['list'][0]['endTime'] # 获取endTime
area =rr_json['data']['list'][0]['area'] # 获取area
payload_z ={'segment' : segment,'day': day,
'startTime': startTime, 'endTime':endTime,
'area':area }
url_zgd='http://***.*.***/Home/Web/area' #进入自习室房间
r = s.get(url_zgd, params=payload_z)
appointment_url='http://***.*.***/api.php/spaces/'+str(space_area)+'/book'
fromdata={
'access_token':access_token, 'userid':userid,
'segment':segment, 'type':1}
appointment=s.post(appointment_url,data=fromdata)
appointment_json=json.loads(appointment.text)
app_msg=appointment_json['msg']
print('%s' %app_msg)
space=appointment_json['data']['list']['spaceInfo']['areaInfo']['parentAreaInfo'] #获取预约信息
print ('%s%s%s'%(space[0]['name'],space[1]['name'],space[2]['name']))
最后附上一张运行成功的图片
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。