Merge pull request #463 from liugangdao/main

fix:翻页时search id不变
This commit is contained in:
程序员阿江(Relakkes) 2024-10-24 15:13:05 +08:00 committed by GitHub
commit 0cd01fbf8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -190,6 +190,7 @@ class XiaoHongShuClient(AbstractApiClient):
async def get_note_by_keyword(
self, keyword: str,
search_id: str = get_search_id(),
page: int = 1, page_size: int = 20,
sort: SearchSortType = SearchSortType.GENERAL,
note_type: SearchNoteType = SearchNoteType.ALL
@ -211,7 +212,7 @@ class XiaoHongShuClient(AbstractApiClient):
"keyword": keyword,
"page": page,
"page_size": page_size,
"search_id": get_search_id(),
"search_id": search_id,
"sort": sort.value,
"note_type": note_type.value
}

View File

@ -31,7 +31,7 @@ from var import crawler_type_var, source_keyword_var
from .client import XiaoHongShuClient
from .exception import DataFetchError
from .field import SearchSortType
from .help import parse_note_info_from_note_url
from .help import parse_note_info_from_note_url, get_search_id
from .login import XiaoHongShuLogin
@ -112,6 +112,7 @@ class XiaoHongShuCrawler(AbstractCrawler):
source_keyword_var.set(keyword)
utils.logger.info(f"[XiaoHongShuCrawler.search] Current search keyword: {keyword}")
page = 1
search_id = get_search_id()
while (page - start_page + 1) * xhs_limit_count <= config.CRAWLER_MAX_NOTES_COUNT:
if page < start_page:
utils.logger.info(f"[XiaoHongShuCrawler.search] Skip page {page}")
@ -123,6 +124,7 @@ class XiaoHongShuCrawler(AbstractCrawler):
note_id_list: List[str] = []
notes_res = await self.xhs_client.get_note_by_keyword(
keyword=keyword,
search_id=search_id,
page=page,
sort=SearchSortType(config.SORT_TYPE) if config.SORT_TYPE != '' else SearchSortType.GENERAL,
)