0

I want to check if an image exists on the given URL using python(urllib2). For example how do I check that an image exists on this url.

https://www.example.com/image.png

If not exist then now its retriving a html content, its not good, i want to check that url has an image then only execute the next code. Sample Code,

        try:
            image = urllib2.urlopen(URL).read()
            image_base64 = base64.encodestring(image)
            Set image if exist
        except:
            default image set
Rohan Nayani
  • 43
  • 3
  • 12
  • What is wrong with your example code pseudo code? Do you not know how to make your example into real code? – Christian Dean Aug 16 '16 at 05:36
  • @Mr.Python i just want to check that url have image source ? some time url redirect index.html so its always return me some values(html/image) but i want to check only images – Rohan Nayani Aug 16 '16 at 06:19
  • @l'L'l thanks for detail information link! but its same like url redirect index.html page so response will always get but i want to check that have image source? – Rohan Nayani Aug 16 '16 at 06:23

0 Answers0