Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib, re, os, sys, time
- #- Arg parsing --------------------------------------#
- sys.argc = len(sys.argv)
- if sys.argc == 2:
- path = ".\\" + str(int(time.mktime(time.gmtime())))
- elif sys.argc == 3:
- path = sys.argv[2]
- else:
- print "Usage: %s <url> [<path>]" % sys.argv[0]
- exit(0)
- #- Fix and check path -------------------------------#
- if not path[-1] == "\\":
- if "\\" in path: path += "\\"
- if not os.path.exists(path):
- os.makedirs(path)
- #- Main program -------------------------------------#
- s = urllib.urlopen("http://4chan.org/b/").read()
- ptrn = "/([a-z]{1,3})/src/([0-9]+\.[gif|jpg|png]+)"
- results = re.findall(ptrn, s)
- for result in results:
- board = result[0]
- img = result[1]
- url = "http://images.4chan.org/%s/src/%s" % (board, img)
- try:
- urllib.urlretrieve(url, path + img)
- print "Succesfully downloaded \"%s\" to path: \"%s\"" % (url, path + img)
- except:
- print "Failed downloading \"%s\" to path: \"%s\"" % (url, path + img)
Add Comment
Please, Sign In to add comment