def getCaptchaImge(): urlStr = 'https://kyfw.12306.cn/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand' # response = session.get(urlStr, headers=headers) response = ngRequest.getRequest(urlStr) if response.status_code == 200: arr = np.asarray(bytearray(response.content), dtype=np.uint8) img = cv2.imdecode(arr, cv2.IMREAD_COLOR) # 'load it as it is' cv2.imwrite(cons.captchaPath, img) return response.status_code
def getTrainRquestList(): startCityCode = cons.getCityCodeWithName('广州南') endCityCode = cons.getCityCodeWithName('长沙') trainDate = '2018-01-13' urlStr = 'https://kyfw.12306.cn/otn/leftTicket/queryZ?leftTicketDTO.train_date=' + trainDate + '&leftTicketDTO.from_station=' + startCityCode + '&leftTicketDTO.to_station=' + endCityCode + '&purpose_codes=ADULT' print(urlStr) response = ngRequest.getRequest(urlStr) # req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36') trainDictList = [] if response.status_code == 200: dic = response.json() # print(dic) result = dic['data']['result'] trainDictList = decoTrainResponse(result) return trainDictList
def getStationName(): url = 'https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.9043' response = ngRequest.getRequest(url) # req = urllib.request.Request(url) # req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36') if response.status_code == 200: html = response.text searchObj = re.match(r'(.*)station_names =\'(.*?)\';', html, re.I) str = searchObj.group(2) array = str.split('@') array.pop(0) for item in array: splis = item.split('|') cityNameDict[splis[1]] = splis[2] cityCodeDict[splis[2]] = splis[1] return response.status_code
def confirmPassenger(): url = 'https://kyfw.12306.cn/otn/confirmPassenger/queryOrderWaitTime?random=1515854548995&tourFlag=dc&_json_att=&REPEAT_SUBMIT_TOKEN=2be399e93d07d8c6ce218b9a6e57f65e' return ngRequest.getRequest(url)
def initMy12306(): urlStr = 'https://kyfw.12306.cn/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand' return ngRequest.getRequest(urlStr)
def logout(): url = 'https://kyfw.12306.cn/otn/login/loginOut' return ngRequest.getRequest(url)