Extract searchable content from Xiaohongshu using one local script.
When to use this skill
- The user wants to search Xiaohongshu content by keyword
- The user wants to batch-extract image links from search results
- The user wants to export search result titles for subsequent topic selection or analysis
- The user needs a repeatable local scraping workflow
Scripts overview
| Script | Purpose | Dependencies |
|---|---|---|
scripts/search.py |
Open the Xiaohongshu search page and extract image links and titles | playwright |
Setup
1. Verify Python
python --version
2. Install dependencies (first run)
pip install playwright
playwright install chromium
Critical error recovery: if a command fails with missing dependency/browser errors, install the missing dependency, then rerun the exact same command.
Usage
Basic search
python scripts/search.py "AI"
Limit extracted items
python scripts/search.py "AI" --count 30
Save output files
python scripts/search.py "AI" --count 30 --save ./output
Parameters
keyword(required): search keyword--count(optional): maximum number of items to extract, default20--save(optional): local output directory
Output
Terminal output
Script prints JSON at the end:
{
"keyword": "AI",
"images": ["https://..."],
"titles": ["..."],
"count": 20
}
Files (when --save is used)
<keyword>_links.txt: list of image links<keyword>_titles.txt: list of titles (written when titles are available)
Execution behavior
- The script opens a browser and visits the Xiaohongshu search page
- If not logged in, it prompts for manual login and waits
- It automatically scrolls the page to load more results before extracting
- It only collects links/titles at the search results level and does not scrape comment threads on detail pages
Limits and edge cases
- Changes to Xiaohongshu's page structure may cause selectors to fail, requiring updates to
scripts/search.py - Login, CAPTCHAs, and risk control policies may affect the scraping success rate
- Different keywords return inconsistent structures; titles may be empty or fewer in number than images
- The script uses a visual browser workflow, not a pure headless API call
Out of scope
This skill does not provide the following capabilities in current repository state:
- Publish image-text/video posts
- Like, comment, reply, and bookmark
- MCP server tool calls
- Login scripts, cover generators, smart publishing scripts
Script reference
- search.py: Xiaohongshu keyword search extractor