Created
October 10, 2016 16:58
-
-
Save ShalbafZadeh/dd5d0e93dc2957c5b006356335fe40c9 to your computer and use it in GitHub Desktop.
Download Oreilly Free books by url
This file contains 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
#license WTFPL | |
#example of usage : python oreilly_downloader.py < url_list | |
#url_list should contain list of urls , a url per line | |
import sys | |
import urllib2 | |
from urllib2 import URLError | |
#making url ready fo download | |
def reformat_url(url): | |
url = url[:url.rfind('?')] | |
return url.replace('.csp','.pdf').replace('/free/','/free/files/') | |
links = [] | |
for line in sys.stdin: | |
links.append((reformat_url(line))) | |
links_list = open('links_list','w') | |
for link in links: | |
print>>links_list , link | |
for link in links : | |
print "DOWNLOADNING " + link | |
try: | |
download_req=urllib2.urlopen(link) | |
download_file = download_req.read() | |
with open(link[link.rfind('/')+1:],"wb") as f: | |
f.write(download_file) | |
#exception occurs mostly because of blank link in end of links file , handling that here | |
except ValueError : | |
pass |
This file contains 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
http://www.oreilly.com/iot/free/ambient-computing.csp | |
http://www.oreilly.com/iot/free/governing-the-iot.csp | |
http://www.oreilly.com/iot/free/iot-opportunities-challenges.csp | |
http://www.oreilly.com/iot/free/what-is-the-internet-of-things.csp | |
http://www.oreilly.com/programming/free/object-oriented-vs-functional-programming.csp?intcmp=il-prog-free-product-lgen_oo_v_fp | |
http://www.oreilly.com/programming/free/hadoop-with-python.csp | |
http://www.oreilly.com/programming/free/how-to-make-mistakes-in-python.csp?intcmp=il-prog-free-product-lgen_python_mistakes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment