Skip to content

Instantly share code, notes, and snippets.

@xatier
Created March 4, 2013 10:28
Show Gist options
  • Save xatier/5081360 to your computer and use it in GitHub Desktop.
Save xatier/5081360 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urllib2
import urlparse
import BeautifulSoup
import os
import re
def find_tags(url):
c = urllib2.urlopen(url).read()
soup = BeautifulSoup.BeautifulSoup(c);
return soup.findAll('img')
def get_src(url, re_):
r = re.compile(re_)
tags = find_tags(url)
for tag in tags:
img = tag['src']
if r.search(img):
yield img
def get_basename(url):
return os.path.basename(urlparse.urlsplit(url)[2])
def download(url, re_=''):
for src in get_src(url, re_):
content = urllib2.urlopen(src).read()
print "[+] download: " + src
file_ = open(get_basename(src) , 'wb')
file_.write(content)
file_.close()
if __name__ == '__main__':
download(url='http://this-plt-life.tumblr.com', re_='gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment