forked from testerSunshine/12306
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetRepeatSubmitToken.py
36 lines (33 loc) · 1.33 KB
/
GetRepeatSubmitToken.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
import json
import re
class getRepeatSubmitToken:
def __init__(self, session):
self.session = session
def sendGetRepeatSubmitToken(self):
"""
获取提交车票请求token
:return: token
"""
initdc_url = self.session.urls["initdc_url"]
initdc_result = self.session.httpClint.send(initdc_url, )
token_name = re.compile(r"var globalRepeatSubmitToken = '(\S+)'")
ticketInfoForPassengerForm_name = re.compile(r'var ticketInfoForPassengerForm=(\{.+\})?')
order_request_params_name = re.compile(r'var orderRequestDTO=(\{.+\})?')
token = re.search(token_name, initdc_result).group(1)
re_tfpf = re.findall(ticketInfoForPassengerForm_name, initdc_result)
re_orp = re.findall(order_request_params_name, initdc_result)
if re_tfpf:
ticketInfoForPassengerForm = json.loads(re_tfpf[0].replace("'", '"'))
else:
ticketInfoForPassengerForm = ""
if re_orp:
order_request_params = json.loads(re_orp[0].replace("'", '"'))
else:
order_request_params = ""
return {
"token": token,
"ticketInfoForPassengerForm": ticketInfoForPassengerForm,
"order_request_params": order_request_params,
"session": self.session
}