Skip to content

Instantly share code, notes, and snippets.

@skagedal
Forked from christopherkullenberg/swepubscraper.py
Created December 29, 2015 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skagedal/dbff704fa28b4db36ab6 to your computer and use it in GitHub Desktop.
Save skagedal/dbff704fa28b4db36ab6 to your computer and use it in GitHub Desktop.
from urllib.request import urlopen
counter = 1
while True:
url = 'http://libris.kb.se/xsearch?d=swepub&hitlist&q=l%C3%A4ros%C3%A4te%3agu&f=ext&spell=true&hist=true&n=200&format=json&start=' + str(counter)
print ("Fetching: " + url)
data = urlopen(url).read()
if not data.find(b'"identifier"') >= 0:
print("No more records!")
break
with open(str(counter) + ".json", "wb") as outputfile:
print("Writing file...")
outputfile.write(data)
counter += 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment