Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from BeautifulSoup import BeautifulSoup
- import urllib
- import sys, os
- html = urllib.urlopen(sys.argv[1])
- soup = BeautifulSoup(html)
- images = soup.findAll('a')
- try:
- dir = sys.argv[2]
- if not os.path.exists(dir): os.mkdir(dir)
- if dir[-1] != '/': dir += '/'
- except:
- dir = ''
- for a in soup.findAll('a'):
- try: # Try & except are there because sometimes the script throws an error and exits
- if '.jpg' in a['href'] or '.png' in a['href'] or '.gif' in a['href']:
- image_name = a['href'].split('/')[-1]
- if os.path.isfile(dir+image_name):
- continue
- else:
- print image_name
- urllib.urlretrieve(a['href'],dir+image_name)
- except:
- continue
Advertisement
Add Comment
Please, Sign In to add comment