"""评论功能"""
from playwright.async_api import Page
from loguru import logger
class CommentFeedAction:
"""评论操作"""
def __init__(self, page: Page):
self.page = page
async def post_comment(
self,
feed_id: str,
xsec_token: str,
content: str
) -> bool:
"""发表评论"""
logger.info(f"Posting comment to feed: {feed_id}")
try:
from xiaohongshu.navigate import make_feed_detail_url
# 导航到详情页
url = make_feed_detail_url(feed_id, xsec_token)
await self.page.goto(url)
await self.page.wait_for_load_state("networkidle")
# 找到评论输入框
comment_input = await self.page.wait_for_selector("textarea.comment-input")
await comment_input.fill(content)
# 点击发送按钮
send_button = await self.page.wait_for_selector("button.send-btn")
await send_button.click()
logger.info("Comment posted successfully")
return True
except Exception as e:
logger.error(f"Failed to post comment: {e}")
return False
async def reply_to_comment(
self,
feed_id: str,
xsec_token: str,
comment_id: str,
content: str
) -> bool:
"""回复评论"""
logger.info(f"Replying to comment: {comment_id}")
try:
# TODO: 实现回复评论逻辑
logger.warning("Reply to comment not fully implemented yet")
return False
except Exception as e:
logger.error(f"Failed to reply to comment: {e}")
return False