123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- from airasia.OrderRelationEntity import OrderRelationEntity,PassengerEntity;
- import json
- import urllib3
- import requests
- import re
- from pyquery import PyQuery as pq
- from utils.HttpUtils import HttpUtils;
- urllib3.disable_warnings()
- headers = {
- 'Accept-Encoding': 'gzip',
- "Content-Encoding": "gzip, deflate, sdch",
- "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6",
- "Upgrade-Insecure-Requests": "1",
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
- "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36",
- }
- #解析出结果信息
- def getResultInfo(html):
- if "|0|hiddenField" in html:
- results = html.index("|0|hiddenField");
- str = html[results:html.__len__()];
- if "|" in str:
- strs = str.split("|");
- for ss in strs:
- if "alert" in ss:
- return ss;
- # 从页面解析参数
- def parserValueFroms(html ):
- jsoup =pq(html);
- __EVENTTARGET = jsoup.find("#eventTarget").attr("value");
- __EVENTARGUMENT = jsoup.find("#eventArgument").attr("value");
- viewState = jsoup.find("#viewState").attr("value");
- __VIEWSTATEGENERATOR = jsoup.find("#__VIEWSTATEGENERATOR").attr("value");
- ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent = jsoup.find("#ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent").attr("value");
- ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword = jsoup.find("#ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword").attr("value");
- froms = {
- "__EVENTARGUMENT":"",
- "__EVENTTARGET":"",
- "__VIEWSTATE":viewState,
- "__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
- "ControlGroupBookingListView$BookingListSearchInputView$DropDownListTypeOfSearch":"0",
- "ControlGroupBookingListView$BookingListSearchInputView$Search":ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent,
- "ControlGroupBookingListView$BookingListSearchInputView$TextBoxKeyword":"KEYWORD",
- "pageToken":""
- };
- return froms;
- # 订单关联
- class OrderRelation():
- def __init__(self,params):
- self.josn_str = params;
- # 转换为实体类字段
- orderRelationEntityDict = json.loads(self.josn_str);
- # print(orderRelationEntityDict);
- result = "";
- self.orderRelationEntity = OrderRelationEntity();
- self.orderRelationEntity.__dict__ = orderRelationEntityDict;
- print(self.orderRelationEntity.singleAccountPassWord)
- self.passengerEntity= PassengerEntity();
- self.passengerEntity.__dict__ =self.orderRelationEntity.passengers;
- print(self.passengerEntity.bigNo)
- def worker(self):
- #代理ip
- proxies = {
- };
- # print("订单开始关联,关联信息为---"+self.josn_str);
- session = requests.session()
- session.headers.update(headers);
- HttpUtils.get(session,"https://www.airasia.com/my/en/login/travel-agent.page",proxies);
- print(session.cookies)
- logindata = {
- "__EVENTARGUMENT": "",
- "__EVENTTARGET": "ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
- "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID": self.orderRelationEntity.singleAccount,
- "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword": self.orderRelationEntity.singleAccountPassWord,
- "pageToken": "",
- "TimeZoneDiff": "480"
- }
- res = HttpUtils.post(session,"https://booking2.airasia.com/LoginAgent.aspx", data=logindata);
- # print(res.content)
- AgentHome = res.url
- htym = res.content.decode()
- aacc = 'window.location.reload'
- print(AgentHome)
- if aacc in htym:
- print('哈哈 需要刷新一下')
- res = session.get(AgentHome)
- htym = res.content.decode()
- else:
- print(htym)
- currencycode = 'default'
- if 'ZENG' in htym:
- print("登录成功")
- print("开始跳转到订单查询页面");
- BookingListGetHtml = HttpUtils.get(session,"https://booking2.airasia.com/BookingList.aspx",proxies=proxies);
- print("进行订单的查询")
- BookingListFroms = parserValueFroms(BookingListGetHtml.content.decode());
- # print(BookingListFroms)
- BookingListPostHtml = HttpUtils.post(session,"https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,proxies=proxies)
- # print(BookingListPostHtml.content.decode())
- # 提交订单
- orderNo = self.orderRelationEntity.orderNo;
- # 解析出表单参数
- BookingListFroms["__EVENTARGUMENT"]="Edit:"+orderNo;
- BookingListFroms["__EVENTTARGET"]="ControlGroupBookingListView$BookingListSearchInputView";
- # print(BookingListFroms)
- BookingListPostHtml2 = HttpUtils.post(session,"https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,proxies=proxies);
- # print(BookingListPostHtml2.url)
- # #
- # ChangeItinerary = HttpUtils.get(session,"https://booking2.airasia.com/ChangeItinerary.aspx",proxies=proxies)
- #
- # BookingListFroms["MemberLoginChangeItineraryView2$TextBoxUserID"]="";
- # BookingListFroms["MemberLoginChangeItineraryView2$PasswordFieldPassword"]="";
- # BookingListFroms["memberLogin_chk_RememberMe"]="";
- # BookingListFroms["HiddenFieldPageBookingData"]=orderNo;
- # BookingListFroms["hdRememberMeEmail"]="";
- # BookingListFroms["__EVENTTARGET"]="ChangeControl$LinkButtonEarnBiggies";
- # BookingListFroms["__EVENTARGUMENT"]="";
- #
- # ChangeItineraryPostHtml = HttpUtils.post(session,"https://booking2.airasia.com/ChangeItinerary.aspx",data=BookingListFroms,proxies=proxies);
- EarnBiggiesGetHtml= HttpUtils.get(session,url="https://booking2.airasia.com/EarnBiggies.aspx",proxies=proxies);
- # print(EarnBiggiesGetHtml.content.decode())
- # 进入出订单关联的url中需要的 hashkey
- EarnBiggiesGetHtmlJsoup = pq(EarnBiggiesGetHtml.content.decode());
- src = EarnBiggiesGetHtmlJsoup.find("#glu").attr("src");
- if src is None:
- print("获取接口地址失败");
- EarnBiggiesGetHtml= HttpUtils.get(session,url="https://booking2.airasia.com/EarnBiggies.aspx",proxies=proxies);
- # 进入出订单关联的url中需要的 hashkey
- EarnBiggiesGetHtmlJsoup = pq(EarnBiggiesGetHtml.content.decode());
- src = EarnBiggiesGetHtmlJsoup.find("#glu").attr("src");
- print("重新获取一次")
- else:
- print(src);
- print("进入订单关联页面")
- src = src.replace("http","https");
- print("替换后的地址为-->"+src);
- PassengerBigIDLiveHtml = HttpUtils.get(session,src,proxies=proxies);
- # 解析表格
- PassengerBigIDLiveHtmlJsoup = pq(PassengerBigIDLiveHtml.content.decode());
- biggridview = PassengerBigIDLiveHtmlJsoup.find(".biggridview");
- # print(biggridview)
- centers = biggridview.html();
- trs = pq(centers).find("tr");
- passengerInfos = [];
- for tr in trs.items():
- passengerInfo = {};
- center=tr.find("td");
- spans = center.find("span");
- for span in spans:
- id = pq(span).attr("id");
- if id.find("firstname")>0:
- passengerInfo.setdefault("firstname",pq(span).text())
- elif id.find("lastname"):
- passengerInfo.setdefault("lastname",pq(span).text())
- key1 = center.find("input[type=hidden]").attr("name");
- key1Value = center.find("input[type=hidden]").attr("value");
- key2 = center.find("input[type=text]").attr("name");
- passengerInfo.setdefault("key1",key1);
- passengerInfo.setdefault("key1Value",key1Value);
- passengerInfo.setdefault("key2",key2);
- if passengerInfo is not None and passengerInfo.__len__() > 0 and passengerInfo.get("firstname") is not None:
- passengerInfos.append(passengerInfo);
- # print(json.dumps(passengerInfos))
- if passengerInfos is None or passengerInfos.__len__() <=0 :
- print("无可关联用户")
- return "无可关联用户";
- print("开始关联");
- PassengerBigIDLiveHtmlJsoup = pq(PassengerBigIDLiveHtml.content.decode());
- __VIEWSTATEGENERATOR = PassengerBigIDLiveHtmlJsoup.find("#__VIEWSTATEGENERATOR").attr("value");
- __VIEWSTATE = PassengerBigIDLiveHtmlJsoup.find("#__VIEWSTATE").attr("value");
- __EVENTVALIDATION =PassengerBigIDLiveHtmlJsoup.find("#__EVENTVALIDATION").attr("value");
- PassengerBigIDLiveHtmlFroms = {
- "ScriptManager1":"MainUpdatePanel|LinkButton1",
- "__EVENTTARGET":"LinkButton1",
- "__EVENTARGUMENT":"",
- "__VIEWSTATE":__VIEWSTATE,
- "__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
- "__EVENTVALIDATION":__EVENTVALIDATION,
- "hfpnr":orderNo,
- "hfurl":"https://member.airasia.com/big-look-up.aspx",
- "__ASYNCPOST":"true"
- }
- # print("passengerInfos--->"+json.dumps(passengerInfos));
- # print("PassengerBigIDLiveHtmlFroms-->"+json.dumps(PassengerBigIDLiveHtmlFroms))
- for centerList in passengerInfos:
- # print("centerList--->"+json.dumps(centerList))
- if centerList.get("firstname") == self.passengerEntity.firstName and centerList.get("lastname")==self.passengerEntity.lastName:
- PassengerBigIDLiveHtmlFroms.setdefault(centerList.get("key1"),centerList.get("key1Value"));
- PassengerBigIDLiveHtmlFroms.setdefault(centerList.get("key2"),self.passengerEntity.bigNo);
- # print(json.dumps(PassengerBigIDLiveHtmlFroms));
- PassengerBigIDLiveHtmlPostResp = HttpUtils.post(session,src,data=PassengerBigIDLiveHtmlFroms,proxies=proxies)
- if "0|error|500||" in PassengerBigIDLiveHtmlPostResp.content.decode():
- #重新请求一次
- PassengerBigIDLiveHtmlPostResp = HttpUtils.post(session,src,data=PassengerBigIDLiveHtmlFroms,proxies=proxies);
- result = getResultInfo(PassengerBigIDLiveHtmlPostResp.content.decode());
- print("结果为-->"+result);
- return result;
|