data science kit

i am a software engineer and data science researcher.

How to download image with python? Just 9 line codes.

Hello everyone! In this post, i’m trying to teach that how to download image from internet with python. Firstly we should import necessesary library. Our necessesary library is urllib.request.

In other hand, we can find image link on internet. I found random 3 image link. You can check as click these links in code block. So, we can create list type variable, because we have lots of image link, and we want to download each image. We need counter variable, thats because we want to define name of downloaded image. (Like image1.jpg, image2.jpg etc.)

Finally we can use most important code line. That function has two parameter. First parameter is link. Second parameter is name of downloaded image. Be careful, you should define extension. (Like .jpg, bmp, png)

Yes thats it, you can review my ready code block.

And you can click here to downlaod how-to-download-image-by-python python file.

[python]
"""
Spyder Editor
Developers are datascikit team.
"""

import urllib.request

imageLink1 = "https://www.freepngimg.com/thumb/donald_trump/2-2-donald-trump-png.png"
imageLink2 = "https://cdn.newsapi.com.au/image/v1/b46c39de749bfa229cf5c0975b74f297?width=700"
imageLink3 = "http://i.hurimg.com/i/hurriyet/75/750x422/5b85040b67b0a81dccef6e63.jpg"

urlList = {imageLink1, imageLink2, imageLink3}

counter = 1

for link in urlList:
    urllib.request.urlretrieve(link, "image" + str(counter)+".jpg")
    counter+=1
"""
Spyder Editor
Developers are datascikit team.
"""
[/python]

If you have any question, i will be happy to hear it. Thanks for care.

« »

© 2020 data science kit. Theme by Anders Norén.