Skip to content

Instantly share code, notes, and snippets.

@El3k0n
Created August 22, 2025 20:06
Show Gist options
  • Select an option

  • Save El3k0n/130268fd406f3a56f5522cad165d46b1 to your computer and use it in GitHub Desktop.

Select an option

Save El3k0n/130268fd406f3a56f5522cad165d46b1 to your computer and use it in GitHub Desktop.
A script I made in 2013 to download all images from a 4chan thread. Works with Python 2.7
#!/usr/bin/env python
#4chan image downloader
import urllib
import re
import sys
import os
usage = """
Usage:
./4chan.py <download dir> <thread>
Example: ./4chan.py /home/user/images/ http://boards.4chan.org/fit/res/13727107
"""
if len(sys.argv) < 3:
print usage
sys.exit()
localfolder = str(sys.argv[1])
if localfolder[-1:] != "/":
localfolder = localfolder + "/"
if os.path.isdir(localfolder) is False:
print "Creating " + localfolder
os.makedirs(localfolder)
downloadurl = sys.argv[2]
imageurl = urllib.urlopen(downloadurl).read()
print "Downloading all images from " + downloadurl
regex = '<a class="fileThumb" href="//(.+?)" target="_blank">'
upattern = re.compile(regex)
images = re.findall(regex, imageurl)
print "Found " + str(len(images)) + " images:"
i = 0
while i < len(images):
image = images[i]
dlurl = "http://" + image
print "Downloading: http://" + image
index1 = image.find("src/")
downloaddir = localfolder + image[index1 + 4:]
urllib.urlretrieve(dlurl, filename=downloaddir )
i += 1
print "Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment