hi all,
I am trying to make a prog. which will download image from a web site.But the problem is the dynamic nature of the web site.
The url is like http://www.site.com/image.aspx?id=445
If i wanna access image 1,2 or anything i can change the id and i can view the pic in my browser.
My prog. is running fine.I am getting the image but the quality of the images is getting very poor.

import urllib
url = 'http://www.site.com/others/getimage.aspx?id=67'
    data = urllib.urlopen(str(url)).read()
    f = open('image.jpg,'w')
    print "Image Generated!!!!"

Is there any other way to Download images from a websites in python.
I have tried it with "WGET"..Its working fine...!!!

Recommended Answers

All 2 Replies

Use urlretrieve .

>>> from urllib import urlretrieve
>>> help(urlretrieve)
Help on function urlretrieve in module urllib:

urlretrieve(url, filename=None, reporthook=None, data=None)


from urllib import urlretrieve
urlretrieve('http://gdimitriou.eu/wp-content/uploads/2008/04/google-image-search.jpg', 'google-image-search.jpg')
commented: It worked fine..Thanks a lot.. +2

it worked great....!!!!!!!!!!Thanks a lot....!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.