123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import urllib3
- import requests
- import re
- import json
- from lxml import etree
- from pyquery import PyQuery as pq
- urllib3.disable_warnings()
- currency = {'DMK': 'THB', 'SIN': 'SGD', 'MFM': 'MOP', 'HKG': 'HKD', 'BWN': 'BND', 'KUL': 'MYR', 'CMB': 'LKR'}
- fromcountry = ['DMK', 'SIN', 'MFM', 'HKG', 'BWN', 'KUL', 'CMB']
- # 国家货币映射
- COUNTRY_TO_CURRENCY = {'BD': 'USD', 'FR': 'EUR', 'BN': 'BND', 'JP': 'JPY', 'HK': 'HKD', 'LA': 'USD', 'TW': 'TWD',
- 'LK': 'LKR', 'NZ': 'NZD', 'TH': 'THB', 'NP': 'NPR', 'PH': 'PHP', 'CN': 'CNY', 'IR': 'USD',
- 'VN': 'USD', 'AU': 'AUD', 'GB': 'GBP', 'IN': 'INR', 'ID': 'IDR', 'MM': 'USD', 'MY': 'MYR',
- 'MO': 'MOP', 'KH': 'USD', 'KR': 'KRW', 'MV': 'USD', 'SA': 'SAR', 'SG': 'SGD', 'LK': 'LKA'}
- 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",
- }
- session = requests.session()
- session.headers.update(headers)
- session.get("https://www.airasia.com/my/en/login/travel-agent.page",verify=False, timeout=30);
- logindata = {
- "__EVENTARGUMENT": "",
- "__EVENTTARGET": "ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
- "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID": "CNTRIPTOPK_ADMIN",
- "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword": "Tripto123",
- "pageToken": "",
- "TimeZoneDiff": "480"
- }
- # proxy = {'http':'192.168.1.30:8001'}
- res = session.post("https://booking2.airasia.com/LoginAgent.aspx", data=logindata, verify=False, timeout=30)
- 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'
- # 从页面解析参数
- 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":__EVENTARGUMENT,
- "__EVENTTARGET":"ControlGroupBookingListView$BookingListSearchInputView$LinkButtonFindBooking",
- "__VIEWSTATE":viewState,
- "__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
- "ControlGroupBookingListView$BookingListSearchInputView$DropDownListTypeOfSearch":"0",
- "ControlGroupBookingListView$BookingListSearchInputView$Search":ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent,
- "ControlGroupBookingListView$BookingListSearchInputView$TextBoxKeyword":ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword,
- "pageToken":""
- };
- return froms;
- if 'ZENG' in htym:
- print('登录成功验证通过')
- # 跳转到订单查询页面
- BookingListGetHtml = session.get("https://booking2.airasia.com/BookingList.aspx",verify=False, timeout=30);
- # 进行订单的查询
- BookingListFroms = parserValueFroms(BookingListGetHtml.content.decode());
- BookingListPostHtml = session.post("https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,verify=False, timeout=30)
- # 提交订单
- orderNo = "CWY1WG";
- # BookingListFroms
- print(BookingListFroms)
- BookingListFroms["__EVENTARGUMENT"]="Edit:"+orderNo;
- BookingListFroms["__EVENTTARGET"]="ControlGroupBookingListView$BookingListSearchInputView";
- print(BookingListFroms)
- BookingListPostHtml2 = session.post("https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,verify=False, timeout=30)
- # 进入订单详情页面
- ChangeItinerary = session.get("https://booking2.airasia.com/ChangeItinerary.aspx",verify=False, timeout=30)
- #
- BookingListFroms["MemberLoginChangeItineraryView2$TextBoxUserID"]="";
- BookingListFroms["MemberLoginChangeItineraryView2$PasswordFieldPassword"]="";
- BookingListFroms["memberLogin_chk_RememberMe"]="";
- BookingListFroms["HiddenFieldPageBookingData"]=orderNo;
- BookingListFroms["hdRememberMeEmail"]="";
- BookingListFroms["__EVENTTARGET"]="ChangeControl$LinkButtonEarnBiggies";
- BookingListFroms["__EVENTARGUMENT"]="";
- ChangeItineraryPostHtml = session.post("https://booking2.airasia.com/ChangeItinerary.aspx",data=BookingListFroms,verify=False, timeout=30)
- EarnBiggiesGetHtml = session.get("https://booking2.airasia.com/EarnBiggies.aspx",verify=False, timeout=30)
- # print(EarnBiggiesGetHtml.content.decode());
- bidId = "7800214292";
- # 进入出订单关联的url中需要的 hashkey
- EarnBiggiesGetHtmlJsoup = pq(EarnBiggiesGetHtml.content.decode());
- src = EarnBiggiesGetHtmlJsoup.find("#glu").attr("src");
- if src is None:
- print("获取地址失败");
- else:
- print(src)
- print("进入订单关联页面")
- src = src.replace("http","https")
- print("替换后的地址为-->"+src)
- # session.headers["Host"]="selfservice.airasia.com";
- print(session.headers)
- PassengerBigIDLiveHtml = session.get(src,verify=False, timeout=300);
- print(session.headers)
- PassengerBigIDLiveHtmlJsoup = pq(PassengerBigIDLiveHtml.content.decode())
- # print(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,
- "GridView1$ctl02$hfid":"0",
- "GridView1$ctl02$txbigshotid":bidId,
- "GridView1$ctl03$hfid":"1",
- "GridView1$ctl03$txbigshotid":"",
- "GridView1$ctl04$hfid":"2",
- "GridView1$ctl04$txbigshotid":"",
- "GridView1$ctl05$hfid":"3",
- "GridView1$ctl05$txbigshotid":"",
- "GridView1$ctl06$hfid":"4",
- "GridView1$ctl06$txbigshotid":"",
- "hfpnr":orderNo,
- "hfurl":"https://member.airasia.com/big-look-up.aspx",
- "__ASYNCPOST":"true"
- }
- print(PassengerBigIDLiveHtmlFroms);
- PassengerBigIDLiveHtmlPostResp = session.post(src,data=PassengerBigIDLiveHtmlFroms,verify=False, timeout=30)
- print(PassengerBigIDLiveHtmlPostResp.content.decode())
- if "0|error|500||" in PassengerBigIDLiveHtmlPostResp.content.decode():
- PassengerBigIDLiveHtmlPostResp = session.post(src,data=PassengerBigIDLiveHtmlFroms,verify=False, timeout=30)
- print(PassengerBigIDLiveHtmlPostResp.content.decode())
- # print(ChangeItinerary.content.decode())
|