Advertisement
Guest User

File With Cookie Scraper

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