Skip to content

Instantly share code, notes, and snippets.

@ricardojob
Last active October 14, 2016 17:18
Show Gist options
  • Save ricardojob/ceb69d9d3723ce2824f7f809aa2cb4cf to your computer and use it in GitHub Desktop.
Save ricardojob/ceb69d9d3723ce2824f7f809aa2cb4cf to your computer and use it in GitHub Desktop.
import re
import requests
def downloadToFile(url):
local = url.split('/')[-1]
r = requests.get(url)
f = open(local, 'wb')
for chunk in r.iter_content(chunk_size=512 * 1024):
if chunk:
f.write(chunk)
f.close()
return
ext = ".epub"
listOfBooks={
'http://www.oreilly.com/programming/free/hadoop-with-python.csp',
'http://www.oreilly.com/programming/free/microservices-for-java-developers.csp'
}
for key in listOfBooks:
retorno = re.search(r"free/(.*?).csp", key).group(0)
book = retorno.split('free/')[1].strip('.csp')
fileName ='http://www.oreilly.com/programming/free/files/'+book+ext
downloadToFile(fileName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment