ZH

2018-06-22  本文已影响0人  FDDDDDDD_
def get_hush_search():
    count = len('64hb58763ce1e6f8fd3c4d39b876f0e6')
    random_list = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f']
    b = ''
    for i in range(0,count):
        a = random.choice(random_list)
        b = b + str(a)
    return b

def get_json_data (url):
    return json.loads(requests.get(url=url,headers=headers).text)

for i in range(0,1000):
    url = 'https://www.zhihu.com/api/v4/search_v3?t=general&q=BAT&correction=1&search_hash_id='+get_hush_search()+'&offset='+str(i)+'&limit=10'
    data_list = get_json_data(url=url)['data']
    print(url)
    for i in data_list:
        print(len(data_list))
        try:
            print(i['object']['question']['name'])
            ID = i['object']['question']['id']
            comment_count = int(i['object']['comment_count'])
            for j in range(0,comment_count,10):
                new_url = 'https://www.zhihu.com/api/v4/questions/' + str(ID) + '/answers?include=data[*].is_normal,admin_closed_comment,reward_info,is_collapsed,annotation_action,annotation_detail,collapse_reason,is_sticky,collapsed_by,suggest_edit,comment_count,can_comment,content,editable_content,voteup_count,reshipment_settings,comment_permission,created_time,updated_time,review_info,relevant_info,question,excerpt,relationship.is_authorized,is_author,voting,is_thanked,is_nothelp,upvoted_followees;data[*].mark_infos[*].url;data[*].author.follower_count,badge[?(type=best_answerer)].topics&offset='+str(j)+'&limit=10&sort_by=default'
                data_li = get_json_data(new_url)['data']
                for answer in data_li:
                    print(answer['author']['name']+'的回答:\n')

                    print(answer['content'])

        except:
            print('None content')
        print('---------------'*10)
上一篇 下一篇

猜你喜欢

热点阅读