Hack Forums
4chan Image Downloader [Python 2] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Grayhat • Purple Team • Hybrid Security (https://hackforums.net/forumdisplay.php?fid=449)
+---- Forum: Website Hacking (https://hackforums.net/forumdisplay.php?fid=43)
+---- Thread: 4chan Image Downloader [Python 2] (/showthread.php?tid=4907195)



4chan Image Downloader [Python 2] - prof.dracula - Jul 15, 2015

Enjoy ✌
Code
#4chan image downloader with thread-rechecking, gif inclusion/exclusion

from bs4 import BeautifulSoup
import urllib2
import time
import os


def imli(url, anim, timer, savepath):
    print "[*] I'll not die til thread is 404'ed :-)"
    count = 0
    while True:
        try:
            content = urllib2.urlopen(url)
        except urllib2.HTTPError, e:
            if e.code == 404:
                print "Oops...Thread 404'ed!"
                return
        board = url.split('/')[3]
        if board == 'b':
            folder = savepath + '/random/' + url.split('/')[-1]
        elif board == 'g':
            folder = savepath + '/technology/' + url.split('/')[-1]
        elif board == 'w':
            folder = savepath + '/animeWallpapers/' + url.split('/')[-1]
        elif board == 'wg':
            folder = savepath + '/wallpapers/' + url.split('/')[-1]
        elif board == 'g':
            folder = savepath + '/literature/' + url.split('/')[-1]
        else:
            folder = savepath + '/board/' + url.split('/')[-1]
        if not os.path.exists(folder):
            os.makedirs(folder)
        html = content.read()
        content.close()
        soup = BeautifulSoup(html)
        links = soup.findAll('a', {'class': 'fileThumb'})
        fimg = []
        for l in links:
            iu = 'http:' + l.get('href')
            if not anim:
                if iu.split('.')[-1].upper() != 'GIF':
                    fimg.append(iu)
            else:
                fimg.append(iu)
        for i in fimg:
            img = i.split('/')[-1]
            if not os.path.exists(folder + '/' + img):
                try:
                    iurl = urllib2.urlopen(i)
                    f = open(folder + '/' + img, 'wb')
                    meta = iurl.info()
                    size = int(meta.getheaders("Content-Length")[0]) / 1024
                    count += 1
                    print "%s -> %s : %s KB" % (count, img, size)
                    f.write(urllib2.urlopen(i).read())
                    f.close()
                except urllib2.HTTPError, e:
                    print "Image not found...Thread 404'ed?"
        time.sleep(timer)
    return


imli(raw_input('Enter thread url:'), False, 15, 'd:/4chan')
raw_input('~Press any key to exit~')
exit(0)



* - BotnetSlave - Jul 18, 2015

How does i t work?
I don't have python, Can someone interpret this in java?


* - SiStemiC - Jul 18, 2015

(Jul 18, 2015 02:04 PM)BotnetSlave Wrote:  How does i t work?
I don't have python, Can someone interpret this in java?

Just download Python man it's free...