顾海波

【需求】导出更多评论

... ... @@ -13,7 +13,7 @@ from openpyxl.styles import Alignment, Font, PatternFill
from .errors import NoFeedDetailError, PageNotAccessibleError, XHSError
from .feed_detail import get_feed_detail
from .search import search_feeds
from .types import Comment, Feed, FilterOption
from .types import Comment, CommentLoadConfig, Feed, FilterOption
logger = logging.getLogger(__name__)
... ... @@ -326,6 +326,7 @@ def poll_comments(
excel_file: str,
feed_index: int | None = None,
delay: float = 1.0,
config: CommentLoadConfig | None = None,
) -> dict:
"""轮询查询评论并保存到 Excel。
... ... @@ -343,6 +344,12 @@ def poll_comments(
if not export.load():
raise FileNotFoundError(f"Excel 文件不存在: {excel_file}")
if config is None:
config = CommentLoadConfig(
click_more_replies=True,
max_comment_items=0,
)
pending_feeds = export.get_pending_feeds()
if feed_index is not None:
... ... @@ -380,7 +387,7 @@ def poll_comments(
try:
# 获取文章详情(含评论)
detail = get_feed_detail(page, feed_id, xsec_token, load_all_comments=True)
detail = get_feed_detail(page, feed_id, xsec_token, load_all_comments=True, config=config)
# 保存评论
for comment in detail.comments.list_:
... ...