Last active
October 10, 2019 02:00
-
-
Save several27/72e72417af260ac17bb0d878e9ea1f52 to your computer and use it in GitHub Desktop.
Download all works from the CrossRef API
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 re | |
from urllib.parse import quote | |
import requests | |
from tqdm import tqdm | |
def main(): | |
with open('crossref.json', 'w') as _out: | |
bar = tqdm() | |
cursor = '*' | |
while True: | |
response = requests.get('http://api.crossref.org/works?rows=1000&cursor=' + cursor) | |
match = re.search(r'\"next-cursor\"\:\"(.*?)\"', response.text) | |
_out.write(response.text + '\n') | |
if not match: | |
break | |
cursor = quote(match.group(1).replace('\\/', '/')) | |
bar.update() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment