Last active
May 14, 2020 07:02
-
-
Save gMan1990/b37f0ad04ee8e8c8a9511bb93b62e6bf to your computer and use it in GitHub Desktop.
zhihu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python | |
import requests | |
headers = { | |
'User-Agent': | |
'', | |
'Cookie': | |
'' | |
} | |
# https://www.zhihu.com/question/383384814/answers/created | |
# sort_by = updated / default / created(desc), limit(max) = 20, offset = 0 | |
next = 'https://www.zhihu.com/api/v4/questions/383384814/answers?sort_by=created&limit=2&include=excerpt' | |
while True: | |
res = requests.get(next, headers=headers) | |
resJson = res.json() | |
#print(resJson) | |
for d in resJson['data']: | |
print(d['excerpt']) # excerpt created_time | |
if resJson['paging']['is_end']: | |
break | |
else: | |
break #next = resJson['paging']['next'] | |
# https://www.zhihu.com/topic/19826365/newest | |
next = 'https://www.zhihu.com/api/v4/topics/19826365/feeds/timeline_activity?limit=20&include=excerpt' | |
res = requests.get(next, headers=headers) | |
resJson = res.json() | |
#print(resJson) | |
for d in resJson['data']: | |
if 'answer' == d['target']['type']: | |
print(d['target']['excerpt']) | |
else: | |
print(d['target']['type']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment