技能圖譜SKILLSGROVE
技能圖譜/短影片與自媒體/kohoj/skills/xiaohongshu-to-markdown

xiaohongshu-to-markdown

安裝

$npx skills add https://github.com/kohoj/skills --skill xiaohongshu-to-markdown
$git clone --depth 1 https://github.com/kohoj/skills.git /tmp/skills && mkdir -p ~/.claude/skills && cp -r /tmp/skills/xiaohongshu-to-markdown ~/.claude/skills/xiaohongshu-to-markdown
請幫我安裝這個 Agent Skill:https://github.com/kohoj/skills/tree/f9ee80710e228d4739f053423a73621b20cc5d09/xiaohongshu-to-markdown ,先閱讀它的 SKILL.md 和指令碼,確認安全後再安裝到我的技能目錄。

簡介

原文描述 · MITXiaohongshu Article to Markdown — Extracts text from Xiaohongshu image-based posts via OCR. Use when the user needs to convert a Xiaohongshu/Little Red Book post into readable Markdown text. The tool downloads all carousel images from a post and uses macOS Vision OCR to extract the text content. Requires a Chromium browser logged into xiaohongshu.com with CDP enabled. macOS only (uses Vision Framework for OCR).
以下 SKILL.md 內容轉載自 kohoj/skills(提交 f9ee807),依據 MIT 許可證轉載正文(文字未改動;僅省略檔案頭後設資料、將圖片顯示為連結,超長內容會截斷);版權歸 2026 kohoj 所有。許可證:LICENSE。僅展示說明檔案,附帶指令碼請在原倉庫檢視。

Xiaohongshu Article to Markdown

Extracts authentication from a Chromium browser via CDP, fetches post data via httpx, downloads carousel images, and OCRs them into a clean Markdown file using macOS Vision Framework.

Quick Start

python3 <skill-path>/scripts/xhs_to_markdown.py <xiaohongshu_url> [--output-dir DIR] [--cdp-port PORT]

Arguments:

  • url (required): Xiaohongshu post URL (e.g., https://www.xiaohongshu.com/explore/...)
  • --output-dir: Output directory, defaults to current working directory
  • --cdp-port: CDP debugging port, default 9222

Output file: {title}_{noteId}.md

Prerequisites

  1. macOS (uses Vision Framework for OCR — no Python OCR dependencies needed)
  2. Chromium-based browser (Chrome / Edge / Brave / Arc) installed and logged in to xiaohongshu.com
  3. Python dependencies: pip install playwright httpx && playwright install chromium
  4. Swift (pre-installed on macOS)

Launch browser with CDP:

# Arc
/Applications/Arc.app/Contents/MacOS/Arc --remote-debugging-port=9222
# Chrome
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
# Edge
/Applications/Microsoft\ Edge.app/Contents/MacOS/Microsoft\ Edge --remote-debugging-port=9222
# Brave
/Applications/Brave\ Browser.app/Contents/MacOS/Brave\ Browser --remote-debugging-port=9222

Architecture

URL → CDP(extract cookies) → httpx(fetch HTML) → parse __INITIAL_STATE__ JSON
→ extract HD image URLs → httpx download images → Swift Vision OCR → Markdown
Step Method Notes
Cookie extraction CDP ctx.cookies() Invisible, no tabs opened
Page fetch httpx GET With browser cookies for auth
Data parsing __INITIAL_STATE__ JSON Embedded in page HTML
Image download httpx concurrent Strips quality compression suffixes
OCR macOS Vision Framework (Swift) .accurate level, zh-Hans + zh-Hant + en
Output Markdown file Title + meta + OCR text + description

Output Format

# {title}

> Author: {author} | {time} | [Original]({url})

{OCR text from image 1}

{OCR text from image 2}

...

---

{post description, if present}

Lessons Learned

Date Lesson Action
檢視許可證全文(MIT)
MIT License

Copyright (c) 2026 kohoj

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.