HttpUtilsTest.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import urllib3
  2. import requests
  3. import re
  4. import json
  5. from lxml import etree
  6. from pyquery import PyQuery as pq
  7. urllib3.disable_warnings()
  8. currency = {'DMK': 'THB', 'SIN': 'SGD', 'MFM': 'MOP', 'HKG': 'HKD', 'BWN': 'BND', 'KUL': 'MYR', 'CMB': 'LKR'}
  9. fromcountry = ['DMK', 'SIN', 'MFM', 'HKG', 'BWN', 'KUL', 'CMB']
  10. # 国家货币映射
  11. COUNTRY_TO_CURRENCY = {'BD': 'USD', 'FR': 'EUR', 'BN': 'BND', 'JP': 'JPY', 'HK': 'HKD', 'LA': 'USD', 'TW': 'TWD',
  12. 'LK': 'LKR', 'NZ': 'NZD', 'TH': 'THB', 'NP': 'NPR', 'PH': 'PHP', 'CN': 'CNY', 'IR': 'USD',
  13. 'VN': 'USD', 'AU': 'AUD', 'GB': 'GBP', 'IN': 'INR', 'ID': 'IDR', 'MM': 'USD', 'MY': 'MYR',
  14. 'MO': 'MOP', 'KH': 'USD', 'KR': 'KRW', 'MV': 'USD', 'SA': 'SAR', 'SG': 'SGD', 'LK': 'LKA'}
  15. headers = {
  16. 'Accept-Encoding': 'gzip',
  17. "Content-Encoding": "gzip, deflate, sdch",
  18. "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6",
  19. "Upgrade-Insecure-Requests": "1",
  20. "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
  21. "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36",
  22. }
  23. session = requests.session()
  24. session.headers.update(headers)
  25. session.get("https://www.airasia.com/my/en/login/travel-agent.page",verify=False, timeout=30);
  26. logindata = {
  27. "__EVENTARGUMENT": "",
  28. "__EVENTTARGET": "ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
  29. "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID": "CNTRIPTOPK_ADMIN",
  30. "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword": "Tripto123",
  31. "pageToken": "",
  32. "TimeZoneDiff": "480"
  33. }
  34. # proxy = {'http':'192.168.1.30:8001'}
  35. res = session.post("https://booking2.airasia.com/LoginAgent.aspx", data=logindata, verify=False, timeout=30)
  36. res.content
  37. AgentHome = res.url
  38. htym = res.content.decode()
  39. aacc = 'window.location.reload'
  40. print(AgentHome)
  41. if aacc in htym:
  42. print('哈哈 需要刷新一下')
  43. res = session.get(AgentHome)
  44. htym = res.content.decode()
  45. else:
  46. print(htym)
  47. currencycode = 'default'
  48. # 从页面解析参数
  49. def parserValueFroms(html ):
  50. jsoup =pq(html);
  51. __EVENTTARGET = jsoup.find("#eventTarget").attr("value");
  52. __EVENTARGUMENT = jsoup.find("#eventArgument").attr("value");
  53. viewState = jsoup.find("#viewState").attr("value");
  54. __VIEWSTATEGENERATOR = jsoup.find("#__VIEWSTATEGENERATOR").attr("value");
  55. ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent = jsoup.find("#ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent").attr("value");
  56. ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword = jsoup.find("#ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword").attr("value");
  57. froms = {
  58. "__EVENTARGUMENT":__EVENTARGUMENT,
  59. "__EVENTTARGET":"ControlGroupBookingListView$BookingListSearchInputView$LinkButtonFindBooking",
  60. "__VIEWSTATE":viewState,
  61. "__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
  62. "ControlGroupBookingListView$BookingListSearchInputView$DropDownListTypeOfSearch":"0",
  63. "ControlGroupBookingListView$BookingListSearchInputView$Search":ControlGroupBookingListView_BookingListSearchInputView_RadioForAgent,
  64. "ControlGroupBookingListView$BookingListSearchInputView$TextBoxKeyword":ControlGroupBookingListView_BookingListSearchInputView_TextBoxKeyword,
  65. "pageToken":""
  66. };
  67. return froms;
  68. if 'ZENG' in htym:
  69. print('登录成功验证通过')
  70. # 跳转到订单查询页面
  71. BookingListGetHtml = session.get("https://booking2.airasia.com/BookingList.aspx",verify=False, timeout=30);
  72. # 进行订单的查询
  73. BookingListFroms = parserValueFroms(BookingListGetHtml.content.decode());
  74. BookingListPostHtml = session.post("https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,verify=False, timeout=30)
  75. # 提交订单
  76. orderNo = "CWY1WG";
  77. # BookingListFroms
  78. print(BookingListFroms)
  79. BookingListFroms["__EVENTARGUMENT"]="Edit:"+orderNo;
  80. BookingListFroms["__EVENTTARGET"]="ControlGroupBookingListView$BookingListSearchInputView";
  81. print(BookingListFroms)
  82. BookingListPostHtml2 = session.post("https://booking2.airasia.com/BookingList.aspx",data=BookingListFroms,verify=False, timeout=30)
  83. # 进入订单详情页面
  84. ChangeItinerary = session.get("https://booking2.airasia.com/ChangeItinerary.aspx",verify=False, timeout=30)
  85. #
  86. BookingListFroms["MemberLoginChangeItineraryView2$TextBoxUserID"]="";
  87. BookingListFroms["MemberLoginChangeItineraryView2$PasswordFieldPassword"]="";
  88. BookingListFroms["memberLogin_chk_RememberMe"]="";
  89. BookingListFroms["HiddenFieldPageBookingData"]=orderNo;
  90. BookingListFroms["hdRememberMeEmail"]="";
  91. BookingListFroms["__EVENTTARGET"]="ChangeControl$LinkButtonEarnBiggies";
  92. BookingListFroms["__EVENTARGUMENT"]="";
  93. ChangeItineraryPostHtml = session.post("https://booking2.airasia.com/ChangeItinerary.aspx",data=BookingListFroms,verify=False, timeout=30)
  94. EarnBiggiesGetHtml = session.get("https://booking2.airasia.com/EarnBiggies.aspx",verify=False, timeout=30)
  95. # print(EarnBiggiesGetHtml.content.decode());
  96. bidId = "7800214292";
  97. # 进入出订单关联的url中需要的 hashkey
  98. EarnBiggiesGetHtmlJsoup = pq(EarnBiggiesGetHtml.content.decode());
  99. src = EarnBiggiesGetHtmlJsoup.find("#glu").attr("src");
  100. if src is None:
  101. print("获取地址失败");
  102. else:
  103. print(src)
  104. print("进入订单关联页面")
  105. src = src.replace("http","https")
  106. print("替换后的地址为-->"+src)
  107. # session.headers["Host"]="selfservice.airasia.com";
  108. print(session.headers)
  109. PassengerBigIDLiveHtml = session.get(src,verify=False, timeout=300);
  110. print(session.headers)
  111. PassengerBigIDLiveHtmlJsoup = pq(PassengerBigIDLiveHtml.content.decode())
  112. # print(PassengerBigIDLiveHtml.content.decode())
  113. __VIEWSTATEGENERATOR = PassengerBigIDLiveHtmlJsoup.find("#__VIEWSTATEGENERATOR").attr("value");
  114. __VIEWSTATE = PassengerBigIDLiveHtmlJsoup.find("#__VIEWSTATE").attr("value");
  115. __EVENTVALIDATION =PassengerBigIDLiveHtmlJsoup.find("#__EVENTVALIDATION").attr("value");
  116. PassengerBigIDLiveHtmlFroms = {
  117. "ScriptManager1":"MainUpdatePanel|LinkButton1",
  118. "__EVENTTARGET":"LinkButton1",
  119. "__EVENTARGUMENT":"",
  120. "__VIEWSTATE":__VIEWSTATE,
  121. "__VIEWSTATEGENERATOR":__VIEWSTATEGENERATOR,
  122. "__EVENTVALIDATION":__EVENTVALIDATION,
  123. "GridView1$ctl02$hfid":"0",
  124. "GridView1$ctl02$txbigshotid":bidId,
  125. "GridView1$ctl03$hfid":"1",
  126. "GridView1$ctl03$txbigshotid":"",
  127. "GridView1$ctl04$hfid":"2",
  128. "GridView1$ctl04$txbigshotid":"",
  129. "GridView1$ctl05$hfid":"3",
  130. "GridView1$ctl05$txbigshotid":"",
  131. "GridView1$ctl06$hfid":"4",
  132. "GridView1$ctl06$txbigshotid":"",
  133. "hfpnr":orderNo,
  134. "hfurl":"https://member.airasia.com/big-look-up.aspx",
  135. "__ASYNCPOST":"true"
  136. }
  137. print(PassengerBigIDLiveHtmlFroms);
  138. PassengerBigIDLiveHtmlPostResp = session.post(src,data=PassengerBigIDLiveHtmlFroms,verify=False, timeout=30)
  139. print(PassengerBigIDLiveHtmlPostResp.content.decode())
  140. if "0|error|500||" in PassengerBigIDLiveHtmlPostResp.content.decode():
  141. PassengerBigIDLiveHtmlPostResp = session.post(src,data=PassengerBigIDLiveHtmlFroms,verify=False, timeout=30)
  142. print(PassengerBigIDLiveHtmlPostResp.content.decode())
  143. # print(ChangeItinerary.content.decode())