BeBeBeBeBörnd

שָׁלוֹם

/usr/local/bin/berndget

#!/usr/bin/env python

import urllib2
import urllib
import BeautifulSoup
import sys
import re
import os

def stripfilename(url):
	base = urllib.unquote(os.path.basename(url))
	return base

def contains(theString, theQueryValue):
	return theString.find(theQueryValue) > -1

def _reporthook(numblocks, blocksize, filesize):
	sys.stdout.write(".")
	sys.stdout.flush()	

request = urllib2.Request(sys.argv[1])
response = urllib2.urlopen(request)
soup = BeautifulSoup.BeautifulSoup(response)
for a in soup.findAll('a'):
	link=a.get('href')
	if (link):
		if (contains(link, "/download/")):
			base=stripfilename(link)
			url="http://krautchan.net"+link
			print url+" --> "+base
			urllib.urlretrieve(url, base, _reporthook)
			print

By Bernd (sometimes under public domain)

Tags: , , ,

Hinterlasse eine Antwort