Skip to content

Instantly share code, notes, and snippets.

@several27
Last active October 10, 2019 02:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save several27/72e72417af260ac17bb0d878e9ea1f52 to your computer and use it in GitHub Desktop.
Save several27/72e72417af260ac17bb0d878e9ea1f52 to your computer and use it in GitHub Desktop.
Download all works from the CrossRef API
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