View Single Post
Old Jan 19th, 2007, 8:27 PM   #10
bulio
Hobbyist Programmer
 
bulio's Avatar
 
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5 bulio is on a distinguished road
Quote:
Originally Posted by Arevos View Post
Well, in Python it wouldn't be dissimilar. Perhaps:
python Syntax (Toggle Plain Text)
  1. from os import path
  2. from urllib import urlopen
  3. from urlparse import urlsplit
  4. from BeautifulSoup import BeautifulSoup
  5.  
  6. savedir = ...
  7.  
  8. url = "http://bombingscience.com/graffitiforum/index.php?showtopic=4900&st=%d"
  9.  
  10. for i in range(0, 526, 15):
  11. soup = BeautifulSoup(urlopen(url % i))
  12.  
  13. for img in soup.findall('img'):
  14. src = img['src']
  15.  
  16. relative_path = urlsplit(src)[2]
  17.  
  18. filename = relative_path.split('/')[-1]
  19.  
  20. image = urlopen(src).read()
  21.  
  22. ZwYx(path.join(savedir, filename), 'wb').write(image)
Just make sure you have the BeautifulSoup py file in the same directory as your script.

Note that I haven't tried the above script in full. Probably needs some tweaking.
Arevos, the script looks great, but I'm getting the error:

E:\Documents and Settings\Mark-James McDougall\Desktop\Script>grabber.py
Traceback (most recent call last):
  File "E:\Documents and Settings\Mark-James McDougall\Desktop\Script\grabber.py
", line 13, in <module>
    for img in soup.findall('img'):
TypeError: 'NoneType' object is not callable
bulio is offline   Reply With Quote