1. #coding=utf-8
    2. import requests,re,datetime,json,sys
    3. reload(sys)
    4. sys.setdefaultencoding("utf-8")
    5. murl = 'https://m.shangri-la.com/v1/mobile?__c=12360172354647'
    6. traveldate = "2019-12-20"
    7. fromdate = datetime.datetime.strptime(traveldate, '%Y-%m-%d')
    8. todate = (fromdate+datetime.timedelta(days=1)).strftime("%Y-%m-%d")
    9. #def getRooms(city="包头",dates="2019-12-20"):
    10. def getRooms(city,fromdate,todate):
    11. headers={}
    12. headers['Content-Type']='application/x-sl-app;ext=0-0-0'
    13. headers['Origin']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
    14. headers['User-Agent']='Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
    15. headers['Referer']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
    16. payload = ('{"service":"hotelEntryService.searchHotel(hotelEntryQuery)","query":{"hotelEntryQuery":{"adultNum":1,"bizType":"SPECIAL_ROOM_SUITE","childNum":0,"checkOutDate":"%s","roomNum":1,"currency":"CNY","specialCodeType":"","type":"CITY","dest":"%s","checkInDate":"%s","specialCode":""}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":null,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"hotelEntryService.searchHotel(hotelEntryQuery)","Content-Type":"application/x-sl-app;ext=0-0-0"}}')%(todate,city,fromdate)
    17. # payload = '{"service":"hotelDetailService.queryHotelDetail(query)","query":{"query":{"adultNum":1,"bizType":"SPECIAL_ROOM_SUITE","childNum":0,"checkOutDate":"2019-12-21","roomNum":1,"currency":"CNY","specialCodeType":"","type":"CITY","dest":"%s","checkInDate":"%s","specialCode":"","hotelCode":"SLBT"}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":0,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"hotelDetailService.queryHotelDetail(query)","Content-Type":"application/x-sl-app;ext=0-0-0"}}'%(city,dates)
    18. #payload["location"] = {"location":"11"}
    19. #print(json.dumps(payload))
    20. resp = requests.post(murl,data=payload,headers=headers)
    21. results = json.loads(resp.content)
    22. #print(resp.content)
    23. if "hotelList" in resp.content:
    24. hotelList = results['data']['hotelList']
    25. for hotel in hotelList:
    26. name = hotel['hotelName']
    27. amount = hotel['price']['amount']
    28. redeemPoints = hotel['redeemPoints']
    29. print(("%s - %s - %s - %s")%(name,amount,redeemPoints,str(int(amount)*1000/int(redeemPoints))))
    30. elif "hotelDetail" in resp.content:
    31. hotel = results['data']['hotelDetail']
    32. name = hotel['name']
    33. amount = hotel['rooms'][0]['roomRate']['originRate']['price']['money']['amount']
    34. redeemPoints = hotel['rooms'][0]['roomRate']['originRate']['redeemPoints']
    35. print(("%s - %s - %s - %s")%(name,amount,redeemPoints,str(int(amount)*1000/int(redeemPoints))))
    36. #print(resp.content)
    37. #getRooms("包头","2019-12-20")
    38. def getallCity():
    39. headers={}
    40. headers['Content-Type']='application/x-sl-app;ext=0-0-0'
    41. headers['Origin']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
    42. headers['User-Agent']='Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
    43. headers['Referer']='https://m.shangri-la.com/v1/mobile?__c=12360172354647'
    44. payload = '{"service":"configService.checkConfigs(query)","query":{"query":{"checkList":[{"version":0,"file":"HotCity.json"},{"version":0,"file":"cityList.json"},{"version":0,"file":"mfaVerifyAlert.json"}],"appCode":"mobile","all":false}},"context":{"appVersion":"2.0.18","os":"","timeZone":"+8:00","packageType":"production","platform":"ANDROID/MW","vendor":"","lang":"Chinese","net":"","brand":"","sh":375,"sw":667,"uuid":"MW-||1575122619175","unionId":null,"mac":"","imei":"","carrier":"","ip":"","downloadChannel":"","source":"M_WEBSITE","dvid":"dw-c770ecf6-62f6-4640-9e69-a79f12c6eac4"},"user":{},"mfa":{"accessTicket":""},"header":{"X-Sl-Service":"configService.checkConfigs(query)","Content-Type":"application/x-sl-app;ext=0-0-0"}}'
    45. #payload["location"] = {"location":"11"}
    46. #print(json.dumps(payload))
    47. resp = requests.post(murl,data=payload,headers=headers)
    48. results = json.loads(resp.content)
    49. #print(resp.content)
    50. citylist = json.loads(results['data']['configs'][1]['dataContent'])
    51. for item in citylist["CN"]:
    52. for cityname in item['citydata']:
    53. cname = cityname.split("|")[0].strip()
    54. try:
    55. getRooms(cname.encode("utf8"),fromdate,todate)
    56. except:
    57. print("Error while:" + cname)
    58. getallCity()