xiaohongshu-skills
Verified小红书(RedNote / Xiaohongshu / XHS / RED / Little Red Book)浏览器自动化技能集合。 支持认证登录、内容发布、搜索发现、账号与评论分析、社交互动和复合运营。 当用户提到小红书、红书、RedNote、Xiaohongshu、XHS、RED、Little Red Book, 或要求发笔记、搜笔记、分析博主、评论、登录、点赞、收藏时触发。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.0 KB |
| scripts/bridge_server.py | script | 5.7 KB |
| scripts/cli.py | script | 49.7 KB |
| scripts/image_downloader.py | script | 4.6 KB |
| scripts/run_lock.py | script | 2.7 KB |
| scripts/title_utils.py | script | 1.7 KB |
| scripts/video_processor.py | script | 7.5 KB |
| scripts/xhs/__init__.py | script | 42 B |
| scripts/xhs/bridge.py | script | 14.0 KB |
| scripts/xhs/cdp.py | script | 27.4 KB |
| scripts/xhs/comment.py | script | 5.8 KB |
| scripts/xhs/cookies.py | script | 1.5 KB |
| scripts/xhs/errors.py | script | 2.3 KB |
| scripts/xhs/feed_detail.py | script | 23.2 KB |
| scripts/xhs/feeds.py | script | 1.1 KB |
| scripts/xhs/human.py | script | 2.1 KB |
| scripts/xhs/like_favorite.py | script | 6.4 KB |
| scripts/xhs/local_discovery.py | script | 2.9 KB |
| scripts/xhs/login.py | script | 11.1 KB |
| scripts/xhs/publish.py | script | 31.9 KB |
| scripts/xhs/publish_long_article.py | script | 8.2 KB |
| scripts/xhs/publish_video.py | script | 4.4 KB |
| scripts/xhs/risk_analyzer.py | script | 11.0 KB |
| scripts/xhs/search.py | script | 6.2 KB |
| scripts/xhs/selectors.py | script | 3.4 KB |
| scripts/xhs/types.py | script | 14.6 KB |
| scripts/xhs/urls.py | script | 958 B |
| scripts/xhs/user_profile.py | script | 9.9 KB |
scripts/image_downloader.py
View on GitHub"""媒体下载(SHA256 缓存),对应 Go pkg/downloader/images.go。"""
from __future__ import annotations
import hashlib
import logging
import os
import time
from urllib.parse import urlparse, urlunparse
import requests
logger = logging.getLogger(__name__)
_USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
)
# 已知图片扩展名
_IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".svg"}
_XHS_CDN_SUFFIX = ".xhscdn.com"
_XHS_REFERER = "https://www.xiaohongshu.com/"
def is_image_url(path: str) -> bool:
"""判断字符串是否为图片/媒体 URL。"""
return path.lower().startswith(("http://", "https://"))
class ImageDownloader:
"""图片下载器(带 SHA256 缓存)。"""
def __init__(self, save_path: str) -> None:
self.save_path = save_path
os.makedirs(save_path, exist_ok=True)
self._session = requests.Session()
self._session.timeout = 30
def download_image(self, image_url: str) -> str:
"""下载单张图片,返回本地文件路径。
如果文件已存在(通过 URL hash 判断),直接返回路径。
Raises:
ValueError: URL 格式无效。
RuntimeError: 下载失败。
"""
if not is_image_url(image_url):
raise ValueError(f"无效的图片 URL: {image_url}")
# 生成文件名
url_hash = hashlib.sha256(image_url.encode()).hexdigest()[:16]
ext = self._detect_extension(image_url)
filename = f"img_{url_hash}_{int(time.time())}{ext}"
filepath = os.path.join(self.save_path, filename)
# 检查是否已有同 hash 的文件
existing = self._find_existing(url_hash)
if existing:
return existing
# 小红书 CDN 的 http 图片链接会被拒绝;保持原路径和签名,仅升级为 https。
request_url = self._secure_xhs_cdn_url(image_url)
parsed = urlparse(request_url)
headers = {
"User-Agent": _USER_AGENT,
"Referer": _XHS_REFERER
if parsed.hostname and parsed.hostname.endswith(_XHS_CDN_SUFFIX)
else f"{parsed.scheme}://{parsed.hostname}/",
}
resp = self._session.get(request_url, headers=headers, timeout=30)
if resp.status_code != 200:
raise RuntimeError(f"下载失败 (status={resp.status_code}): {request_url}")
# 保存
with open(filepath, "wb") as f:
f.write(resp.content)
logger.info("下载完成: %s -> %s", image_url, filepath)
return filepath
@staticmethod
def _secure_xhs_cdn_url(image_url: str) -> str:
"""仅将小红书 CDN 的 http 链接升级为 https,避免改变 URL 签名。"""
parsed = urlparse(image_url)
if parsed.scheme == "http" and parsed.hostname and parsed.hostname.endswith(_XHS_CDN_SUFFIX):
return urlunparse(parsed._replace(scheme="https"))
return image_url
def download_images(self, image_urls: list[str]) -> list[str]:
"""批量下载图片。"""
paths = []
for url in image_urls:
try:
path = self.download_image(url)
paths.append(path)
except Exception as e:
logger.error("下载失败 %s: %s", url, e)
return paths
def _detect_extension(self, url: str) -> str:
"""从 URL 推断文件扩展名。"""
parsed = urlparse(url)
path = parsed.path.lower()
for ext in _IMAGE_EXTENSIONS:
if path.endswith(ext):
return ext
return ".jpg" # 默认
def _find_existing(self, url_hash: str) -> str | None:
"""查找已有同 hash 的文件。"""
prefix = f"img_{url_hash}_"
for filename in os.listdir(self.save_path):
if filename.startswith(prefix):
return os.path.join(self.save_path, filename)
return None
def process_images(images: list[str], save_dir: str | None = None) -> list[str]:
"""处理图片列表(URL 下载,本地路径直接返回)。"""
if not save_dir:
save_dir = os.path.join(os.path.expanduser("~"), ".xhs", "images")
downloader = ImageDownloader(save_dir)
result = []
for img in images:
if is_image_url(img):
path = downloader.download_image(img)
result.append(path)
else:
# 本地路径
if os.path.exists(img):
result.append(os.path.abspath(img))
else:
logger.warning("文件不存在: %s", img)
return result
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |