import mechanize, os
from BeautifulSoup import BeautifulSoup

browser = mechanize.Browser()
html = browser.open(url)
soup = BeautifulSoup(html)
image_tags = soup.findAll('img')
for image in image_tags:
    filename = image['src'].lstrip('http://')
    filename = os.path.join(dir, filename.replace('/', '_'))
    data = browser.open(image['src']).read()
    browser.back()
    save = open(filename, 'wb')
    save.write(data)
    save.close()
