Created
May 22, 2018 05:38
-
-
Save paultopia/1e2c3e48e870a5da6262854329028aef to your computer and use it in GitHub Desktop.
download humble book bundle
This file contains hidden or 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
| # 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