Retrieve image of url to jpg file
Question: 
    from urllib.request import urlopen
    from shutil import copyfileobj
    
    sh='''http://www.stockcharts.com/h-sc/ui?s=GLD'''
    floc= '''c:/files/python/texts/sh.jpg'''
    
    with urlopen (sh) as str ,open (floc,'wb')as outf:
         copyfileobj(str,outf)
    

This code does not produce a valid jpg file.  
Is there another way of coding it?


Answer: **Problem:**

Your problem is the fact that your program is not working with an image URL.

**Solution:** You want to parse the html from the site then using wildcards
get the IMG Url link then use that for your program.(to note that site uses
.Png) The below code is just an example of the downloading the image not the
Html stuff (I'm new to coding myself)

    
    
    import random
    import urllib.request
    
    def download_web_image(url):
        name = random.randrange(1,1000)
        full_name = str(name) + ".png"
        urllib.request.urlretrieve(url,full_name)
    
    img_url = input('Please Insert Image Url you wish to download: ')
    
    download_web_image(img_url)
    

