コード例 #1
0
ファイル: Login.py プロジェクト: xzgxp/EasyTrain
 def _init(self):
     url = r'https://kyfw.12306.cn/otn/login/init'
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': r'https://kyfw.12306.cn/otn/index/initMy12306',
         'Connection': 'keep-alive',
     }
     NetUtils.get(self.__session, url, headers=headers)
コード例 #2
0
ファイル: Login.py プロジェクト: xzgxp/EasyTrain
 def _userLogin(self):
     url = r'https://kyfw.12306.cn/otn/login/userLogin'
     params = {
         '_json_att': '',
     }
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Content-Type': 'application/x-www-form-urlencoded',
         'Referer': 'https://kyfw.12306.cn/otn/login/init',
     }
     NetUtils.get(self.__session, url, params=params, headers=headers)
コード例 #3
0
 def _payOrderInfo(self):
     url = r'https://kyfw.12306.cn/otn/payOrder/init?random=%d' % (time.time() * 1000)
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Connection': 'keep-alive',
     }
     response = NetUtils.get(self.__session, url, headers=headers).text
コード例 #4
0
    def _getExtraInfo(self):
        url = r'https://kyfw.12306.cn/otn/confirmPassenger/{}'.format(
            '%s' % ('initWc' if self.__ticket.tourFlag == TourFlag.GO_BACK else
                    'initDc'))
        print(url)

        def getRepeatSubmitToken(html):
            repeatSubmitToken = re.findall(
                r"var globalRepeatSubmitToken = '(.*)'", html)[0]
            print('RepeatSubmitToken = %s' % repeatSubmitToken)
            return repeatSubmitToken

        html = NetUtils.get(self.__session,
                            url,
                            headers={
                                'User-Agent': FIREFOX_USER_AGENT,
                                'Connection': 'keep-alive',
                            }).text
        # print('getExtraInfo', html)
        self.__ticket.repeatSubmitToken = getRepeatSubmitToken(html)

        def decodeTicketInfoForPassengerForm(html):
            ticketInfoForPassengerForm = re.findall(
                r'var ticketInfoForPassengerForm=(.*);', html)[0]
            return json.loads(ticketInfoForPassengerForm.replace("'", "\""))

        self.__ticket.ticketInfoForPassengerForm = decodeTicketInfoForPassengerForm(
            html)
コード例 #5
0
ファイル: Login.py プロジェクト: xzgxp/EasyTrain
 def _passportRedirect(self):
     url = r'https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin'
     params = {
         'redirect': '/otn/login/userLogin',
     }
     headers = {
         'Accept':
         'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
         'Accept-Encoding': 'gzip, deflate, br',
         'Accept-Language': 'en-US,en;q=0.5',
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': 'https://kyfw.12306.cn/otn/login/init',
         'Connection': 'keep-alive',
         'Upgrade-Insecure-Requests': '1',
     }
     NetUtils.get(self.__session, url, params=params, headers=headers)
コード例 #6
0
ファイル: Query.py プロジェクト: xzgxp/EasyTrain
 def query(session,
           trainDate,
           fromStation,
           toStation,
           passengerType=PASSENGER_TYPE_ADULT):
     params = {
         r'leftTicketDTO.train_date': trainDate,
         r'leftTicketDTO.from_station': city2code(fromStation),
         r'leftTicketDTO.to_station': city2code(toStation),
         r'purpose_codes': passengerType
     }
     # response = NetUtil.normalGet(Query.__url, params=params, headers={'User-Agent': random.choice(USER_AGENT)}).json()
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': r'https://kyfw.12306.cn/otn/leftTicket/init',
         'Connection': 'keep-alive',
     }
     response = NetUtils.get(session,
                             Query.__url,
                             params=params,
                             headers=headers,
                             verify=False)
     print(response.text)
     response = response.json()
     response = response['data'] if 'data' in response else Log.e(
         "can not find key: 'data'")
     queryResults = response['result'] if 'result' in response else Log.e(
         "can not find key: 'result'")
     return Query.__decode(queryResults, passengerType)
コード例 #7
0
ファイル: Submit.py プロジェクト: weaming/EasyTrain
 def _payOrderInfo(self):
     url = r"https://kyfw.12306.cn/otn//payOrder/init?random=%10d" % (
         time.time() * 1000)
     headers = {
         "User-Agent": FIREFOX_USER_AGENT,
         "Connection": "keep-alive"
     }
     response = NetUtils.get(self.__session, url, headers=headers).text
コード例 #8
0
 def _payOrderInfo(self):
     url = r'https://kyfw.12306.cn/otn//payOrder/init?random=%10d' % (
         time.time() * 1000)
     headers = {
         'User-Agent':
         'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0',
         'Connection': 'keep-alive',
     }
     response = NetUtils.get(self.__session, url, headers=headers).text
コード例 #9
0
 def _queryOrderWaitTime(self):
     url = r'https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime'
     params = {
         'random': '%10d' % (time.time() * 1000),
         'tourFlag': self.__ticket.ticketInfoForPassengerForm['tour_flag']
         or 'dc',
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': self.__ticket.repeatSubmitToken,
     }
     headers = {
         'User-Agent': FIREFOX_USER_AGENT,
         'Referer': r'https://kyfw.12306.cn/otn/confirmPassenger/initDc',
         'Connection': 'keep-alive',
     }
     response = NetUtils.get(self.__session,
                             url,
                             params=params,
                             headers=headers).json()
     print('queryOrderWaitTime: %s' % response)
     return response['status'], response['messages'], response['data']['waitTime'], response['data']['orderId'], \
            response['data']['msg'] if 'msg' in response['data'] else None