Skip to content

Instantly share code, notes, and snippets.

@no13bus
Last active August 29, 2015 14:27
Show Gist options
  • Save no13bus/985a85b908027e5cc1ce to your computer and use it in GitHub Desktop.
Save no13bus/985a85b908027e5cc1ce to your computer and use it in GitHub Desktop.
toutiao api
import requests
import datetime
from bs4 import BeautifulSoup
def get_posts_by_day(date_str)
url='http://toutiao.io/prev/%s' % date_str
r=requests.get(url)
c=r.content
soup = BeautifulSoup(c)
posts=soup.find_all('div', 'post')
for post in posts:
link=post.find('div', 'content').h3.a.attrs['href']
title=post.find('div', 'content').h3.a.text
sumary=post.find('div', 'content').p.a.text
upvote=post.find('a','like-button').span.text
print link, title, sumary
if __name__=='__main__':
now = datetime.datetime.now()
last_date = now-datetime.timedelta(days=1)
last_date = last_date.strftime('%Y-%m-%d')
get_posts_by_day(last_date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment