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.

Spyder Editor
Developers are datascikit team.

import urllib.request

imageLink1 = ""
imageLink2 = ""
imageLink3 = ""

urlList = {imageLink1, imageLink2, imageLink3}

counter = 1

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

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

« »

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