import requests headers = { "accept": "application/json, text/plain, */*", "accept-language": "zh-CN,zh;q=0.9", "cache-control": "no-cache", "culture": "zh-HK", "origin": "https://www.jetstar.com", "pragma": "no-cache", "priority": "u=1, i", "referer": "https://www.jetstar.com/", "sec-ch-ua": "\"Google Chrome\";v=\"135\", \"Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Windows\"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "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" } def search_flight_date(): """查询航班日期, 即那天有航班""" url = "https://digitalapi.jetstar.com/v1/farecache/flights/batch/availability-with-fareclasses" params = { "flightCount": "1", "includeSoldOut": "true", "requestType": "StarterOnly", "from": "2025-05-26", # 采集开始时间 "end": "2025-05-27", # 采集结束时间,可随意写 "departures": "CTS", "arrivals": "KOJ", "direction": "outbound", "paxCount": "1", "includeFees": "false" } response = requests.get(url, headers=headers, params=params, verify=False) response.raise_for_status() print(response.json()) # for i in response.json(): # print(i) json_data = response.json()[0]['routes'] for key, val in json_data.items(): flight_dates = list(val.get('flights', {}).keys()) print(f'航段: {key} 对应有航班的日期为: {flight_dates}') search_flight_date()