X Thread Scrape
Use this skill when you need reproducible capture of:
- Seed tweet full text
- Same-author continuation posts in the thread
- Related image URLs and downloaded image files
Language guides:
- Chinese guide: references/usage_zh.md
- English guide: references/usage_en.md
Workflow
- Install dependency (if missing):
pip install patchright
Prepare cookie file in Netscape format (example:
H:\cookies\x.txt).Run script:
python E:\projectHome\skill_grok\skill\x-thread-scrape\scripts\query_x_thread.py `
--cookie-file H:\cookies\x.txt `
--tweet-url "https://x.com/<handle>/status/<tweet_id>" `
--output-dir E:\projectHome\skill_grok `
--basename x_thread_result `
--wait-seconds 240
- Check outputs:
<basename>_thread.json: structured thread output (tweets + images info)<basename>_posts.jsonl: one tweet per line<basename>_meta.json: run metadata and output paths<basename>_images/: downloaded images
Script
Use query_x_thread.py.
Key flags:
--cookie-file: Netscape cookie txt path (required)--tweet-url: X seed tweet URL (required)--output-dir: output directory (default.)--basename: output prefix (defaultx_thread_result)--wait-seconds: max thread expansion wait (default180)--max-scrolls: scroll attempts to load thread continuation (default30)--scroll-wait-ms: wait per scroll (default1500)--headless: run browser headless--include-all-authors: include non-seed-author tweets--no-download-images: keep image URLs only, skip image downloads
Thread Semantics
Default behavior captures tweets authored by the same handle as the seed tweet URL.
Use --include-all-authors if you want replies from other authors too.
Failure Handling
If thread capture is incomplete:
- Increase
--wait-secondsand--max-scrolls. - Run without
--headlessto inspect the page behavior. - Refresh cookie file and retry.
If image download fails:
- Keep the image
source_urlandnormalized_urlfrom JSON as ground truth. - Retry with stable network or another cookie session.