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)
def query(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 } jsonRet = EasyHttp.send(queryUrls['query'], params=params) try: if jsonRet: return Query.__decode(jsonRet['data']['result'], passengerType) except Exception as e: Log.e(e) return []
def query(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, } jsonRet = EasyHttp.send(queryUrls["query"], params=params) try: if jsonRet: return Query.__decode(jsonRet["data"]["result"], passengerType) except Exception as e: Log.e(e) return []
def __query(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 = NetUtils.normalGet(Query.__url, params=params, headers={ 'User-Agent': random.choice(USER_AGENT) }).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)