feat(xhs): add "collect" crawler type to fetch collected/收藏 notes#933
Open
dake6767 wants to merge 2 commits into
Open
feat(xhs): add "collect" crawler type to fetch collected/收藏 notes#933dake6767 wants to merge 2 commits into
dake6767 wants to merge 2 commits into
Conversation
Adds a new CRAWLER_TYPE="collect" for Xiaohongshu that crawls the logged-in user's collected (收藏) notes. Previously only search, detail and creator modes were supported, so there was no way to export one's own collection. - client: get_self_user_id() via /api/sns/web/v2/user/me, plus get_notes_by_collect() / get_all_notes_by_collect() hitting /api/sns/web/v2/note/collect/page - core: dispatch branch + get_collected_notes(), reusing the existing note-detail + comment pipeline - config: XHS_COLLECT_USER_ID_LIST (empty = own collection; may also list bare user_ids or full profile URLs for others' public collections) - cmd_arg: add CrawlerTypeEnum.COLLECT
- tests/test_xhs_collect.py: `--type collect` is accepted (not downgraded to search), empty XHS_COLLECT_USER_ID_LIST resolves the logged-in user's own id, and a configured profile URL is parsed into user_id + xsec_token - README: document `--type collect` and XHS_COLLECT_USER_ID_LIST usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
CRAWLER_TYPE="collect"for Xiaohongshu that crawls thelogged-in user's collected (收藏) notes. Previously the xhs crawler only
supported
search/detail/creator, so there was no way to exportyour own 收藏.
How
get_self_user_id()resolves the numericuser_idvia/api/sns/web/v2/user/me(note:selfinfoonly returnsred_id, not thenumeric
user_idthe collect API needs), plusget_notes_by_collect()/get_all_notes_by_collect()paging/api/sns/web/v2/note/collect/page.get_collected_notes(), reusing theexisting note-detail / media / comment pipeline — so
ENABLE_GET_COMMENTS,CRAWLER_MAX_NOTES_COUNT, and all storage backends work unchanged.XHS_COLLECT_USER_ID_LIST(empty = own collection; or listbare
user_ids / full profile URLs withxsec_tokenfor others' publiccollections) and
CrawlerTypeEnum.COLLECTincmd_arg(otherwise theconfig value silently falls back to
search).Usage
python main.py # or: python main.py --platform xhs --type collectOutput goes to the usual
data/xhs/...sink (jsonl/csv/db/...), written ascollect_contents_*/collect_comments_*.Testing
Verified end-to-end against a live logged-in account: resolves the
user_id,pages the collection, fetches note details + comments, and writes the output
files. Only xhs implements
collect; other platforms treat the type as ano-op via the existing
elsebranch, so nothing else is affected.