import requests
import time
import math
import demjson
comment_request = [{'thread_id': '11817919873', 'qid': '96177926', 'rid': '2954479968'}, {'thread_id': '1260090477', 'qid': '96177926', 'rid': '315022619'}, {'thread_id': '1260687497', 'qid': '96177926', 'rid': '315171874'}, {'thread_id': '11734823241', 'qid': '96177926', 'rid': '2933705810'}, {'thread_id': '1260108277', 'qid': '96177926', 'rid': '315027069'}]
def get_new_comment(param):
t = str(math.floor(time.time()))
# url = "https://zhidao.baidu.com/api/comment?method=get_new_comment&app=qb&thread_id=1260090477&qid=96177926&rid=2954479968"
url = "https://zhidao.baidu.com/api/comment?method=get_new_comment&app=qb&thread_id=" + param['thread_id'] + "&qid=" + param['qid'] + "&rid=" + param['rid'] + "&pn=0&rn=10&r=" + t
print(url)
# url = "https://zhidao.baidu.com/api/comment?method=get_new_comment&app=qb&thread_id=11817919873&qid=96177926&rid=2954479968&pn=0&rn=10&r=" + t
resp = requests.post(url)
comment = resp.json()
if comment['data']['comment_count'] != None:
for item in comment['data']['comment_list']:
str_create_time = item['str_create_time']
content = item['content']
from_uname = item['from_uname']
from_uid = item['from_uid']
to_uid = item['to_uid']
id = param['rid']
print(str_create_time, content, from_uname, from_uid, to_uid, id)
for req in comment_request:
get_new_comment(req)