web scraping - how to download image into a folder python
Question: I have this code where i would like to download the image and save it into a
folder but i am getting the src of the image.I have gone through stack
overflow where i found this [Batch downloading text and images from URL with
Python / urllib /
beautifulsoup?](http://stackoverflow.com/questions/7918239/batch-downloading-
text-and-images-from-url-with-python-urllib-beautifulsoup) but have no idea
how to proceed

Here is my code,so far i have tried

    
    
    elm5=soup.find('div', id="dv-dp-left-content")
    img=elm5.find("img")
    src = img["src"]
    print src
    

How can i download these images using url into a folder


Answer: 
    import urllib
    
    f = open('local_file_name','wb')
    f.write(urllib.urlopen(src).read())
    f.close()
    

`src` have to be full path - for
example`http://hostname.com/folder1/folder2/filename.ext`.

If `src` is `/folder1/folder2/filename.ext` you have to add
`http://hostname.com/`.  
If `src` is `folder2/filename.ext` you have to add
`http://hostname.com/folder1/`.  
etc.

* * *

**EDIT:** example how to download StackOverflow logo :)

    
    
    import urllib
    
    f = open('stackoverflow.png','wb')
    f.write(urllib.urlopen('http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b').read())
    f.close()
    

