enrich(ctrip): expand the adapter across Ctrip's travel verticals#2156
Merged
Conversation
Benjamin-eecs
marked this pull request as ready for review
July 19, 2026 14:47
Benjamin-eecs
marked this pull request as draft
July 19, 2026 15:30
Benjamin-eecs
marked this pull request as ready for review
July 19, 2026 22:38
Benjamin-eecs
marked this pull request as draft
July 20, 2026 02:27
Benjamin-eecs
marked this pull request as ready for review
July 20, 2026 11:19
ctrip search already suggests railway stations but there was no way to query the actual departures. ctrip train <from> <to> --date fills that gap on the public trains.ctrip.com list page, browser-mode + cookie like flight/hotel-search. Rows are read by stable class-keyed fields rather than positional innerText; incomplete cards are dropped, not sentinel-filled.
Single-hotel profile from the detail-page SSR: rating sub-scores, hot facilities, check-in/out policy.
Intercity coach search via the newbus results deep link (landing SPA does not hydrate under the bridge).
Passenger ferry sailings via the ship.ctrip.com results deep link, sibling of bus.
Resolves a departure port name to its legacy per-port code, then reads the .route_info cards.
Group and self-guided tour search via the vacations sv=<destination> deep link, stable-class cards.
Shares the vacations product extractor with tour (freetravel section); folds a 万 count multiplier into the shared parser.
…esults Matches the drift handling bus/ferry/train use, so genuine-empty stays EmptyResultError.
parseListLimit / parsePlaceName replace the train-named helpers now reused across bus/ferry/cruise/tour/package with neutral hints; ferry ship-name/duration read by pattern, not position.
jackwener
force-pushed
the
enrich/ctrip-train
branch
from
July 20, 2026 17:49
a55fd5a to
8a819b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Rounds out the
ctripadapter across the travel verticals Ctrip exposes with a stable extraction surface, tracked by #2155. The adapter already covered flights, hotels, and destination suggest; this PR adds seven verticals in one place rather than one command per PR. Each command follows the shape the adapter already uses (browser mode plusStrategy.COOKIE; the publicsearch/hotel-suggestcommands resolve the ids the search commands take), reads rows from stable SSR or class-keyed anchors, drops incomplete rows rather than surfacing blanks, and raisesAuthRequiredErroron a captcha / login gate.Verticals shipped in this PR (each live-verified, output below):
trainhotelsingle-hotel detail (hotel-searchalready shipped)busferrycruisetourpackageattraction(a destination's top attractions by city id)flight-roundWhile finalizing this PR, Ctrip migrated its flight list from
.flight-list > span > divto.flight-itemcards (which omit a text flight number), which had silently broken the existing one-wayctrip flight. Bothflightandflight-roundnow read the new cards through the shared parser, withflightNoreturned asnullwhen a card omits it.Closes #2155.
Type of Change
Checklist
Documentation (if adding/modifying an adapter)
docs/adapters/(if new adapter)docs/adapters/index.mdtable (if new adapter)docs/.vitepress/config.mts(if new adapter)README.md/README.zh-CN.mdwhen command discoverability changedCliErrorsubclasses instead of rawErrorScreenshots / Output
Trains (火车票):
trainLive run against trains.ctrip.com (logged-in session, no captcha):
Also verified on a normal-speed K-type route (杭州 to 上海) so high-speed and normal trains both parse. Rows missing the train number or endpoint times are dropped, never surfaced with sentinel values;
fromPricestaysnullwhen the price node is non-numeric. Captcha redirect raisesAuthRequiredError; render timeout / malformed extraction raiseCommandExecutionError; a genuinely empty route raisesEmptyResultError;--limit(1-50) is validated up front with no silent clamp. Train helpers are appended toclis/ctrip/utils.jsafter the existing flight helpers, so this does not touch the flight-card extractor that PR #2142 is revising.Hotels (酒店):
hotelLive run against hotels.ctrip.com (logged-in session, no captcha):
The profile is read from
__NEXT_DATA__.props.pageProps.hotelDetailResponse, the same SSR source style ashotel-search, and surfaces the four rating sub-scores, hot facilities, and the check-in/out policy that the listing row does not carry. Room-level nightly prices load via a post-SSR XHR into hashed CSS-module cards, so they are out of scope here the same wayflight's post-load price XHR is.Bus (汽车票):
busLive run against bus.ctrip.com (logged-in session, no captcha):
The
bus.ctrip.com/landing SPA does not hydrate under the browser bridge, so the command navigates the results route directly through its?param=<json>deep link (the payload the app's own search handler posts). Coach rows arrive via thebusListV2XHR and are read from.list-item-parentcards by stable utility-class fields; rows missing the departure time or either station are dropped rather than surfaced with blanks.Ferry (船票):
ferryLive run against ship.ctrip.com (logged-in session, no captcha):
Sibling of
busonship.ctrip.com: same non-hydrating landing, same?param=<json>results deep link. Sailings arrive via thegetShipLineV2XHR and are read from.list-item-parentcards; rows missing the departure time or either port are dropped rather than surfaced with blanks.Cruise (邮轮):
cruiseLive run against cruise.ctrip.com (logged-in session, no captcha):
Cruise results live on the legacy
newpackage/search/sN.htmlpages keyed by an opaque per-port code, so the command loads the 上海 page (which lists every port as a link) to resolve the requested port name to its code, then loads that port's results and reads the.route_infocards. A listed port with no current sailings (verified against 天津, currently seasonal) raisesEmptyResultError. River cruises are a separate product and out of scope.Tours (旅游):
tourLive run against vacations.ctrip.com (logged-in session, no captcha):
Results render server-side into
.list_product_itemcards read by stable class fields; the price / score / sold fields lazy-load a moment after the titles, so the command waits until every rendered card carries a price before reading. A destination with no packages raisesEmptyResultError.Flight and Hotel (机+酒):
packageLive run against vacations.ctrip.com (logged-in session, no captcha):
Reuses the shared vacations product extractor against the
freetravel(自由行 / flight-plus-hotel) search section rather than thewholesectiontouruses;sold/reviewscounts written asN万are folded to their integer value.Attractions (门票):
attractionLive run against you.ctrip.com (logged-in session, no captcha):
The you.ctrip.com place page renders through hashed CSS-module class names, so rows anchor on the one stable handle each attraction exposes, the
/sight/<city>/<id>.htmldetail link (name is the text before the rating,urlits href), and read rating / review count from the link text by data-format pattern (19.7w/1.3万expanded to thousands). The place page routes by the trailing numeric city id (discover it viactrip search) and redirects any slug to the canonical one;ratingstaysnullwhen a card lists only a review count. Per-attraction ticket prices sit on each sight's own detail page and are out of scope here.Round-trip flights (往返机票):
flight-roundLive run against flights.ctrip.com (logged-in session, no captcha):
The round-trip search deep-links to the same
online/listapp under around-<from>-<to>?depdate=<depart>_<return>URL that renders the outbound (去程) leg priced for the whole round trip (往返总价). The cards are.flight-itemrows carrying the same ordered text shape as the one-way list, so this reuses the one-way position-anchored parser with that selector; the round-trip cards omit the flight number, soflightNo/aircraftcome backnull(never a sentinel) and the parser treats them as optional there while keeping them required for the one-way list. Picking the return leg is a second step and is out of scope here.All nine shipped verticals above are live-verified against a logged-in session;
clis/ctrip/ctrip.test.jscovers each command's argument validation, captcha / timeout / empty / malformed ladder, and JSDOM extraction. The out-of-scope verticals are noted with their reasons in the Description.