Sixem

Python - 8chan Image Downloader

Nov 7th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Usage: 8c.py "http://www.8chan.co/*/res/*.html" "download/location"
  3. __author__ = 'Sixem'
  4. import sys
  5. from BeautifulSoup import BeautifulSoup
  6. import urllib2
  7. import re
  8. import math
  9. cmdargs = str(sys.argv)
  10. req = urllib2.Request(str(sys.argv[1]), headers={'User-Agent' : "Fozilla Mirefox"})
  11. html = urllib2.urlopen(req)
  12. soup = BeautifulSoup(html)
  13. imgs = soup.findAll("p", {"class":"fileinfo"})
  14. cimg = len(imgs)
  15. cc = 0
  16. print ("Found: %s images! Starting download." % cimg)
  17. for img in imgs:
  18.         cc += 1
  19.         i = (img.a['href'])
  20.         req = urllib2.Request(i, headers={'User-Agent' : "Fozilla Mirefox"})
  21.         u = urllib2.urlopen(req)
  22.         print ("[%s] %s" % (("%s/%s" % (cc, cimg)), i))
  23.         sFile = open(('%s/%s' % (str(sys.argv[2]), i.split('/')[-1])), 'w')
  24.         sFile.write(u.read())
  25.         sFile.close()
  26. print 'All done!'
Add Comment
Please, Sign In to add comment