Last active
April 8, 2018 19:03
-
-
Save cquest/5817731dd6342574480ac5f80f4e8f52 to your computer and use it in GitHub Desktop.
python script to retrieve a user's curated scoops on scoop.it
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
import json | |
import requests | |
from bs4 import BeautifulSoup | |
import sys | |
scoop = sys.argv[1] # ex: https://www.scoop.it/u/user-login | |
pages = int(sys.argv[2]) # number of pages to retrieve | |
for page in range(0, pages): | |
req = requests.get(scoop + "/ajaxGetLastPublishedPosts?showPaginator=truelistId=curatedPostsTab&view=json&page=%s" % (page+1,)) | |
j = json.loads(req.text) | |
h = BeautifulSoup(j['js_inner_replace']['html'], 'lxml') | |
for post in h.find_all(class_='post'): | |
try: | |
meta = post.find(class_='post-metas') | |
out = dict() | |
out['url'] = post.h2.a.get('href') | |
out['title'] = post.h2.a.text.strip() | |
out['meta'] = meta.span.a.get('href') | |
out['date'] = meta.span.a.text.strip() | |
print(json.dumps(out)) | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment