Comments.py 513 B

1234567891011121314151617181920
  1. import requests
  2. import json
  3. def get_comments(id, page, cookie, user_agent):
  4. params = {
  5. 'id': id,
  6. 'page': page,
  7. 'moduleID': 'feed',
  8. 'count': 10 if page == 1 else 20
  9. }
  10. headers = {
  11. 'Cookie': cookie,
  12. 'User_Agent': user_agent
  13. }
  14. url = 'https://weibo.com/ajax/statuses/repostTimeline?' # 请求api
  15. res = requests.get(url, params=params, headers=headers).content
  16. res_json = json.loads(res)
  17. res_data = res_json['data']
  18. return res_data