Python script to download pictures/Jpegs/jpgs from a website

Here is script to download images, from a website. I have taken the example of to download the images to my local disk.
you can alter it as you please:
import sgmllib
import re
class MyParser(sgmllib.SGMLParser):
A simple parser class.
def parse(self, s):
Parse the given string s.
def __init__(self, verbose=0):
Initialise an object, passing verbose to the superclass.
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
def start_a(self, attributes):
Process a hyperlink and its attributes.
for name, value in attributes:
if name == href:
def get_hyperlinks(self):
Return the list of hyperlinks.
return self.hyperlinks
import urllib, sgmllib
# Get something to work with.
f = urllib.urlopen(
s =
# Try and process the page.
# The class should have been defined first, remember.
myparser = MyParser()
# Get the hyperlinks.
#print myparser.get_hyperlinks()
hlist = myparser.get_hyperlinks()
for links in hlist:
var_extn = links[-3:]
if(var_extn == jpg):
finalURL =
print finalURL
start = finalURL.find(480x640_)
end = finalURL.find(.jpg)
finalName = finalURL[start:end]
image = urllib.URLopener()

Leave a Reply

Your email address will not be published. Required fields are marked *