Skip to content

Instantly share code, notes, and snippets.

@saikatkumardey
Created September 18, 2014 12:03
Show Gist options
  • Save saikatkumardey/73ed4468063637f7c0de to your computer and use it in GitHub Desktop.
Save saikatkumardey/73ed4468063637f7c0de to your computer and use it in GitHub Desktop.
PDF downloader
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