Skip to content

Instantly share code, notes, and snippets.

@paultopia
Created May 22, 2018 05:38
Show Gist options
  • Select an option

  • Save paultopia/1e2c3e48e870a5da6262854329028aef to your computer and use it in GitHub Desktop.

Select an option

Save paultopia/1e2c3e48e870a5da6262854329028aef to your computer and use it in GitHub Desktop.
download humble book bundle
# first run the following line of javascript (minus the comment hashtag) in your browser console
# JSON.stringify(Array.prototype.slice.call(document.getElementsByTagName('a')).map(x => x.href).filter(x => x.indexOf("pdf") + x.indexOf("mobi") + x.indexOf("epub") !== -3))
# then right-click output of that, copy to clipboard, and paste into text editor as urls.json.
# I'm assuming you're using firefox here, if not, it might do something different---particularly, the double json load below handles the wonky output that firefox produces with a json wrapped in a string
# (come to think of it you can probably just read it and `loads` that, but whev.
# anyway, then run this. donezie.
import requests, json, os
from urllib.parse import urlparse
with open("urls.json") as urls:
files = json.loads(json.load(urls))
browheader = {'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7"}
def get_and_save_file(url):
resp = requests.get(url, headers=browheader)
filename = os.path.basename(urlparse(url).path)
with open(filename, 'wb') as file:
file.write(resp.content)
for x in files:
get_and_save_file(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment