feat: rewrite scrapeThread to use TweetDetail GraphQL API#17
Closed
nj-io wants to merge 2 commits intonirholas:mainfrom
Closed
feat: rewrite scrapeThread to use TweetDetail GraphQL API#17nj-io wants to merge 2 commits intonirholas:mainfrom
nj-io wants to merge 2 commits intonirholas:mainfrom
Conversation
Replace DOM-based thread scraping with direct GraphQL API calls. X doesn't render self-reply threads as article elements in the DOM, causing empty results — especially for high-engagement tweets. The new approach: - Calls TweetDetail GraphQL API from the page context using session cookies - Gets full_text (no truncation, no "Show more" needed) - note_tweet support for long-form posts - Filters to self-reply chain only (author replying to themselves) - Chronological sorting Also introduces shared helpers for future use by scrapePost: - fetchTweetDetail() — GraphQL API caller - parseTweetResult() — rich data extraction (text, media, article, card, external URLs, engagement stats) - parseThreadFromEntries() — thread chain detection - extractEntries(), unwrapResult(), getScreenName() Fixes: - screen_name moved from user.legacy to user.core in X's GraphQL schema - Self-replies missing from API response for viral tweets (2000+ replies) now handled gracefully (returns available tweets) Supersedes nirholas#12 which patches the DOM approach — this replaces it entirely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@nj-io is attempting to deploy a commit to the kaivocmenirehtacgmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
nj-io
added a commit
to nj-io/XActions
that referenced
this pull request
Apr 5, 2026
New scrapePost() function and x_read_post MCP tool that reads any
tweet URL with full rich data and recursive quote tweet resolution.
Features:
- Single tweets or threads (auto-detected via self-reply chain)
- Rich data per tweet: text, media (images + best-quality video URL),
X Articles (title + cover image + URL), cards (link previews),
external URLs (Substack, GitHub, etc.), engagement stats
- Recursive quote tweet resolution — if a quoted tweet is itself a
thread, or contains its own quote tweet, those are fetched too
(up to 5 levels deep)
- Uses shared helpers from scrapeThread rewrite (fetchTweetDetail,
parseTweetResult, parseThreadFromEntries)
Return shape:
{ thread: [{ id, author, text, timestamp, url, media, article,
card, urls, replies, retweets, likes, views, quotedPost? }] }
Where quotedPost has the same { thread: [...] } shape, recursively.
Depends on: nirholas#17 (scrapeThread GraphQL rewrite with shared helpers)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 tasks
- Replace uniform randomDelay (1-3s) with log-normal distribution (2-7s base + 8% distraction spikes of 8-20s) - Add checkAuth() guard after page navigation — fails fast on expired cookies - Add randomDelay before each fetchTweetDetail API call to simulate human browsing between tweet reads
nj-io
added a commit
to nj-io/XActions
that referenced
this pull request
Apr 5, 2026
New scrapePost() function and x_read_post MCP tool that reads any tweet URL with full rich data and recursive quote tweet resolution. Features: - Single tweets or threads (auto-detected via self-reply chain) - Rich data per tweet: text, media (images + best-quality video URL), X Articles (title + cover image + URL), cards (link previews), external URLs (Substack, GitHub, etc.), engagement stats - Recursive quote tweet resolution — if a quoted tweet is itself a thread, or contains its own quote tweet, those are fetched too (up to 5 levels deep) - Human-like delays between API calls (inherited from fetchTweetDetail) - Auth check on navigation (inherited from shared helpers) Depends on: nirholas#17 (scrapeThread GraphQL rewrite with shared helpers) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nj-io
added a commit
to nj-io/XActions
that referenced
this pull request
Apr 6, 2026
… filtering Replace the broken DOM-based x_get_likes with a proper scraper using the Likes GraphQL API (cursor-based pagination). - 50 tweets in ~14s, 200 in ~49s (was capped at ~25 with DOM scraping) - Rich data via parseTweetResult (text, media, articles, cards, URLs, engagement) - JSONL output to ~/.xactions/exports/ — progress survives crashes - from/to timestamp filters with early exit on reverse chronological data - Removes x_get_likes from xeepyTools, routes through local-tools.js Depends on: nirholas#17 (shared helpers: parseTweetResult, checkAuth, randomDelay) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6 tasks
nj-io
added a commit
to nj-io/XActions
that referenced
this pull request
Apr 6, 2026
…likes Two new scrapers and MCP tools: scrapeLikedTweets — GraphQL-based likes scraper: - Cursor pagination via Likes API (50 tweets in 14s, 200 in 49s) - JSONL output to ~/.xactions/exports/ - from/to timestamp filtering with early exit - Rich data via parseTweetResult discoverLikes — interleaved fetch + deep read: - Fetches likes via API, deep-reads each via scrapePost - Human-like pacing: 3-8s between pages, 2-5s before reads, 5-15s after - Produces two JSONL files: likes index + deep reads - ~38s per tweet average (5 likes = 190s) Both remove x_get_likes from xeepyTools and delete the old DOM handler. Depends on: nirholas#17 (shared helpers), nirholas#18 (scrapePost) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 tasks
Author
|
Superseded — resubmitting as clean PRs from current codebase. |
6 tasks
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.
Summary
Replaces the DOM-based
scrapeThreadwith direct TweetDetail GraphQL API calls. X doesn't render self-reply threads asarticle[data-testid="tweet"]elements in the DOM, causing the current scraper to return empty results — especially for tweets with many replies.Why the DOM approach fails
screen_namemoved fromuser.legacytouser.corein X's GraphQL schema, breaking author detectionNew approach
TweetDetailGraphQL API directly from the page context viafetch()full_textfrom the API (no truncation, no "Show more" clicking needed)note_tweetsupport for long-form posts (>280 chars)Shared helpers
Introduces helper functions designed for reuse by a future
scrapePosttool:fetchTweetDetail(page, tweetId)parseTweetResult(result)parseThreadFromEntries(entries, author, tweetId)extractEntries(data)unwrapResult(result)TweetWithVisibilityResultswrappergetScreenName(result)user.coreanduser.legacypathsBackward compatibility
scrapeThreadreturn shape is unchanged — internal fields (media,article,card,urls,quotedTweetId,inReplyTo) are stripped before returning, so existing consumers see the same{ id, text, author, timestamp, url, isMainAuthor, platform }shape.Relation to other PRs
scrapePost/x_read_postPR that will use the shared helpers to read any post with full rich data and recursive quote tweet resolutionTest plan
🤖 Generated with Claude Code