Search Trip.com for one-way flights and return the flight-result cards without navigating through the homepage or search form.
Use Cases
Use when the caller provides origin and destination airport codes, departure date, passenger composition, cabin, and optionally sort order, locale, currency, or a specific displayed fare policy.
Automation Flow
- Construct the results URL directly, taking the locale domain from the caller and defaulting to
trip.com. The observed run used{locale-domain}ofjp.trip.com:https://{locale-domain}/flights/showfarefirst?dcity={origin-code}&acity={destination-code}&ddate={YYYY-MM-DD}&class={cabin-code}&triptype=OW&quantity={total-passengers}&childqty={child-passengers-as-trip-classified}&babyqty={infant-passengers}&sort={sort}&locale={locale}&curr={currency} - Optionally append
&midpolicyid={url-encoded-policy-id}only when the caller requests a particular displayed fare. Policy IDs observed by Trip.com use the form{variant}:{origin-code}-{destination-code}:{flight-number}; read the exact value from the page or fare-selection state and URL-encode it rather than inventing one. - Navigate to the constructed URL and wait for
[data-shoppinginfoid]result cards to render. - In the same browser call, run this extractor on the loaded page:
(() => {
const clean = s => (s || '').replace(/\s+/g, ' ').trim();
const cards = [...document.querySelectorAll('[data-shoppinginfoid]')]
.map(card => {
const button = card.querySelector('button[data-testid="u_select_btn"]');
const airlines = [...card.querySelectorAll('[aria-label]')]
.map(e => clean(e.getAttribute('aria-label')))
.filter(Boolean);
const flightNumbers = [...card.querySelectorAll('[data-crawl-flight-no]')]
.map(e => clean(e.getAttribute('data-crawl-flight-no')))
.filter(Boolean);
const flightNames = [...card.querySelectorAll('[data-testid="flights-name"]')]
.map(e => clean(e.innerText))
.filter(Boolean);
return {
shoppingInfoId: card.getAttribute('data-shoppinginfoid'),
text: clean(card.innerText),
airlines: [...new Set(airlines)],
flightNumbers: [...new Set(flightNumbers)],
flightNames: [...new Set(flightNames)],
selectLabel: button ? clean(button.innerText) : null
};
})
.filter(x => x.shoppingInfoId && x.text);
return { url: location.href, flights: cards };
})()Possible Friction Points
dcityandacitytake airport codes, whileddateusesYYYY-MM-DD.quantityis the total traveler count;childqtyandbabyqtyare separate Trip.com passenger-category counts. In the observed flow, a 12-year-old was represented asquantity=3&childqty=0for two adults plus that traveler, so follow Trip.com's age classification rather than assuming every minor belongs inchildqty.class=Yis economy andtriptype=OWis one-way.sort=pricesorts the result list by price.- Result cards expose their opaque fare identifier in
data-shoppinginfoid; do not infer or fabricate this identifier. Airline names may appear on descendants with Japanesearia-labelvalues. - Flight numbers can be extracted from descendant elements carrying
data-crawl-flight-no; displayed carrier/flight labels can also occur under[data-testid="flights-name"]. - A selected fare detail can append an opaque
midpolicyidquery parameter to the same results URL. Values follow a pattern such as1:{origin}-{destination}:{flight-number}, but the complete value must be captured from Trip.com; only add it when a caller specifically requests a particular displayed fare. - Results are dynamically rendered, so wait for the cards or
[data-shoppinginfoid]elements before extraction. - Fare selection may open a modal through
button[data-testid="u_select_btn"]; prefer the directmidpolicyidURL when the exact policy identifier is already known, avoiding modal interaction.