flight_date_search.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import requests
  2. headers = {
  3. "accept": "application/json, text/plain, */*",
  4. "accept-language": "zh-CN,zh;q=0.9",
  5. "cache-control": "no-cache",
  6. "culture": "zh-HK",
  7. "origin": "https://www.jetstar.com",
  8. "pragma": "no-cache",
  9. "priority": "u=1, i",
  10. "referer": "https://www.jetstar.com/",
  11. "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"",
  12. "sec-ch-ua-mobile": "?0",
  13. "sec-ch-ua-platform": "\"Windows\"",
  14. "sec-fetch-dest": "empty",
  15. "sec-fetch-mode": "cors",
  16. "sec-fetch-site": "same-site",
  17. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36"
  18. }
  19. def search_flight_date():
  20. """查询航班日期, 即那天有航班"""
  21. url = "https://digitalapi.jetstar.com/v1/farecache/flights/batch/availability-with-fareclasses"
  22. params = {
  23. "flightCount": "1",
  24. "includeSoldOut": "true",
  25. "requestType": "StarterOnly",
  26. "from": "2025-05-26", # 采集开始时间
  27. "end": "2025-05-27", # 采集结束时间,可随意写
  28. "departures": "CTS",
  29. "arrivals": "KOJ",
  30. "direction": "outbound",
  31. "paxCount": "1",
  32. "includeFees": "false"
  33. }
  34. response = requests.get(url, headers=headers, params=params, verify=False)
  35. response.raise_for_status()
  36. print(response.json())
  37. # for i in response.json():
  38. # print(i)
  39. json_data = response.json()[0]['routes']
  40. for key, val in json_data.items():
  41. flight_dates = list(val.get('flights', {}).keys())
  42. print(f'航段: {key} 对应有航班的日期为: {flight_dates}')
  43. search_flight_date()