From c522075341560a40e7e077780436d9250e2ed2b4 Mon Sep 17 00:00:00 2001 From: Perry Huang Date: Tue, 11 Aug 2026 00:18:45 +0800 Subject: [PATCH] fix: fall back to search page when homepage lacks ondemand.s X redesigned its homepage to use React Router (TSR), which no longer contains the ondemand.s file reference. This causes ClientTransaction init to fail, leading to 404s on search and other endpoints that require x-client-transaction-id header. The search page (x.com/search?q=AI&f=live) has NOT been redesigned and still uses the legacy responsive-web/client-web/ frontend with ondemand.s. This PR adds a fallback: if the homepage does not contain ondemand.s, automatically fetch the search page and use it for ClientTransaction initialization. Fixes #78, complements #79 --- twitter_cli/client.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/twitter_cli/client.py b/twitter_cli/client.py index 0436c8e..68e7707 100644 --- a/twitter_cli/client.py +++ b/twitter_cli/client.py @@ -1109,7 +1109,23 @@ def _ensure_client_transaction(self): home_page_response = bs4.BeautifulSoup(home_page.content, "html.parser") ondemand_url = get_ondemand_file_url(response=home_page_response) if not ondemand_url: - raise ValueError("Failed to extract ondemand file URL from homepage") + # X redesigned its homepage; the search page still has the + # legacy frontend with ondemand.s. Fall back to it. + search_page = cffi_session.get( + "https://x.com/search?q=AI&f=live", + headers=ct_headers, timeout=10, + ) + search_response = bs4.BeautifulSoup( + search_page.content, "html.parser" + ) + ondemand_url = get_ondemand_file_url(response=search_response) + if not ondemand_url: + raise ValueError( + "Failed to extract ondemand file URL from homepage " + "and search page" + ) + home_page_response = search_response + home_page = search_page ondemand_file = cffi_session.get( ondemand_url, headers=ct_headers, timeout=10, )