Created
September 18, 2014 12:03
-
-
Save saikatkumardey/73ed4468063637f7c0de to your computer and use it in GitHub Desktop.
PDF downloader
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
import urllib2 | |
import sys | |
import os | |
from subprocess import call | |
try: | |
url = sys.argv[1] | |
k= urllib2.urlopen(url).readlines() | |
file_name= "random_file.txt" | |
op= open(file_name,'w') | |
for i in k: | |
if '<a' in i and '.pdf' in i: | |
pos_i= i.find('\"') | |
pos_j= i.find('\"',pos_i+1) | |
op.write(i[pos_i+1:pos_j]+'\n') | |
op.close() | |
call(["wget","-i",file_name]) | |
os.remove(file_name) | |
except: | |
print "Error in connection. Please check URL again. " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment