더 큰 Xiaohongshu Note 배치 비동기 처리

작성자

카테고리:

← 피드로
DEV Community · mian po · 2026-07-18 개발(SW)

mian po

Process A Larger Note Batch Asynchronously

Synchronous batches are convenient for a small request. For up to 50 complete public note URLs, use the asynchronous workflow so the client does not hold one gateway request open.

Start with XHS Data API on RapidAPI and keep the RapidAPI key on your server.

Submit A Job

import os
import time
import requests

base_url = "https://xiaohongshu-rednote-data-api.p.rapidapi.com"
headers = {
    "X-RapidAPI-Key": os.environ["X_RAPIDAPI_KEY"],
    "X-RapidAPI-Host": "xiaohongshu-rednote-data-api.p.rapidapi.com",
    "Content-Type": "application/json",
}
urls = [os.environ["XHS_NOTE_URL"]]

response = requests.post(
    f"{base_url}/note/async_batch_detail_from_url",
    headers=headers,
    json={"urls": urls, "count": len(urls), "raw": False},
    timeout=30,
)
response.raise_for_status()
job = response.json()["data"]
print("job_id:", job["job_id"])

Enter fullscreen mode Exit fullscreen mode

Poll At The Recommended Interval

while job["status"] in {"queued", "running"}:
    time.sleep(job.get("poll_after_seconds", 2))
    response = requests.get(
        f"{base_url}/note/async_batch_detail_result",
        headers=headers,
        params={"job_id": job["job_id"]},
        timeout=30,
    )
    response.raise_for_status()
    job = response.json()["data"]

print(job["status"], job["success"], job["failed"])

Enter fullscreen mode Exit fullscreen mode

Stop polling when status is succeeded, partial, or failed. Results preserve per-item successes when another URL fails. Jobs process URLs sequentially, survive normal service restarts, and expire after 24 hours.

Never expose job_id as an authorization mechanism. Keep RapidAPI authentication server-side and store only the job metadata your application needs.

Download the complete clients and retry helpers from the developer website or review the public examples repository.

XHS Data API is independent and is not affiliated with or endorsed by Xiaohongshu/RedNote. Use public data lawfully and follow applicable law, third-party rights, and source-platform rules.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다