Last active
June 7, 2018 06:32
-
-
Save 2niuhe/43fe0183d17a9c7205244b14465806c6 to your computer and use it in GitHub Desktop.
It's a python script works on liunx shell,which can help you read zhihu-daily news.可以帮助你在终端下浏览知乎日报。http://blog.niuhemoon.xyz/pages/2018/05/18/zhihu-daily-crawler/
This file contains 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
#!/usr/bin/python3 | |
#-*- coding: utf-8 -*- | |
import requests | |
import json | |
headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} | |
def get_daily(): | |
page = requests.get('http://news-at.zhihu.com/api/3/news/latest', headers=headers).text | |
response = json.loads(page) | |
date = response['date'] | |
stories = response['stories'] | |
date = '\n%s年%s月%s日' % (date[:4], date[4:6], date[6:]) | |
print('%s 共%d条日报\n' % (date, len(stories))) | |
for index,story in enumerate(stories, 1): | |
print('{0:<2d}:{1:s}\n url:http://news-at.zhihu.com/story/{2:d}'.format(index, story['title'], story['id'])) | |
if __name__ == '__main__': | |
get_daily() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment