Volkova

desu.py

Jul 20th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. from BeautifulSoup import BeautifulSoup
  2. import urllib
  3. import sys, os
  4.  
  5. html = urllib.urlopen(sys.argv[1])
  6. soup = BeautifulSoup(html)
  7. images = soup.findAll('a')
  8.  
  9. try:
  10.     dir = sys.argv[2]
  11.     if not os.path.exists(dir): os.mkdir(dir)
  12.     if dir[-1] != '/': dir += '/'
  13. except:
  14.     dir = ''
  15.  
  16. for a in soup.findAll('a'):
  17.     try: # Try & except are there because sometimes the script throws an error and exits
  18.         if '.jpg' in a['href'] or '.png' in a['href'] or '.gif' in a['href']:
  19.             image_name = a['href'].split('/')[-1]
  20.             if os.path.isfile(dir+image_name):
  21.                 continue
  22.             else:
  23.                 print image_name
  24.                 urllib.urlretrieve(a['href'],dir+image_name)
  25.     except:
  26.         continue
Advertisement
Add Comment
Please, Sign In to add comment