Skip to content

Commit

Permalink
MOD:小红书去掉cusor必须参数
Browse files Browse the repository at this point in the history
  • Loading branch information
ShilongLee committed Jun 20, 2024
1 parent e2d816a commit 308b794
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion docs/api/xhs/xhs.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
|:---:|:---:|:---:|:---:|
| id | true | string | 小红书笔记id,从网页链接中获取,例如: 6653f0820000000005005f9b |
| comment_id | true | string | 笔记评论id,从评论中获得到的id,例如: 6654b9ac000000001c015031 |
| cursor | true | string | 笔记评论游标id,从评论中获得到的sub_comment_cursor,例如: 66551bdb000000001c0248d1 |
| offset | false | int | 评论翻页偏移量, 默认0 |
| limit | false | int | 评论数量, 默认20 |

Expand Down
3 changes: 2 additions & 1 deletion service/xhs/logic/replys.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from .common import common_request
def request_replys(id: str, comment_id: str, cursor: str, cookie: str, offset: int = 0, limit: int = 20) -> tuple[dict, bool]:
def request_replys(id: str, comment_id: str, cookie: str, offset: int = 0, limit: int = 20) -> tuple[dict, bool]:
"""
请求小红书获取评论回复信息
"""
headers = {"cookie": cookie}
end_length = offset + limit
comments = []
has_more = True
cursor = ''
while has_more and len(comments) < end_length:
data = {
"note_id": id,
Expand Down
7 changes: 3 additions & 4 deletions service/xhs/views/replys.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ def replys():
"""
id = request.args.get('id', '')
comment_id = request.args.get('comment_id', '')
cursor = request.args.get('cursor', '')
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 10))
_accounts = accounts.load()
random.shuffle(_accounts)
for account in _accounts:
if account.get('expired', 0) == 1:
continue
res, succ = request_replys(id, comment_id, cursor, account.get('cookie', ''), offset, limit)
res, succ = request_replys(id, comment_id, account.get('cookie', ''), offset, limit)
if not succ:
accounts.expire(account.get('id', ''))
if res == {} or not succ:
continue
logger.info(f'get reply success, id: {id}, comment_id: {comment_id}, cursor: {cursor}, offset: {offset}, limit: {limit}, res: {res}')
logger.info(f'get reply success, id: {id}, comment_id: {comment_id}, offset: {offset}, limit: {limit}, res: {res}')
return reply(ErrorCode.OK, '成功' , res)
logger.warning(f'get reply failed, id: {id}, comment_id: {comment_id}, cursor: {cursor}, offset: {offset}, limit: {limit}')
logger.warning(f'get reply failed, id: {id}, comment_id: {comment_id}, offset: {offset}, limit: {limit}')
return reply(ErrorCode.INTERNAL_ERROR, '内部错误请重试')

0 comments on commit 308b794

Please sign in to comment.