Advertisement
Guest User

filesDownload

a guest
Nov 28th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import urllib2
  2. import urllib
  3. from cookielib import CookieJar
  4.  
  5. files = 'http://www.nytimes.com/interactive/2014/11/25/us/evidence-released-in-michael-brown-case.html?_r=0'
  6. slashpos = 0
  7.  
  8. def getLinks(url):
  9. cj = CookieJar()
  10. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  11. p = opener.open(url)
  12. result = []
  13. for line in p:
  14. for element in line.split():
  15. if element.startswith('href="http://gr'):
  16. if element.endswith('pdf"') or element.endswith('png"') or element.endswith('jpg"'):
  17. result.append(element[6:])
  18. for char in result:
  19. slashpos = char.rfind('/') + 1
  20. urllib.urlretrieve(char, char[slashpos:-1])
  21.  
  22. getLinks(files)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement