Skip to content

Instantly share code, notes, and snippets.

@gMan1990
Last active May 14, 2020 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gMan1990/b37f0ad04ee8e8c8a9511bb93b62e6bf to your computer and use it in GitHub Desktop.
Save gMan1990/b37f0ad04ee8e8c8a9511bb93b62e6bf to your computer and use it in GitHub Desktop.
zhihu
# 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