import requests import json def get_comments(id, page, cookie, user_agent): params = { 'id': id, 'page': page, 'moduleID': 'feed', 'count': 10 if page == 1 else 20 } headers = { 'Cookie': cookie, 'User_Agent': user_agent } url = 'https://weibo.com/ajax/statuses/repostTimeline?' # 请求api res = requests.get(url, params=params, headers=headers).content res_json = json.loads(res) res_data = res_json['data'] return res_data