Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to download the image using python

I have following xpath for YT comment owner’s thumbnail.

<a class="yt-simple-endpoint style-scope ytd-comment-renderer" href="/channel/UCX6OQ3DkcsbYNE6H8uQQuVA">
      <yt-img-shadow fit="" height="40" width="40" class="style-scope ytd-comment-renderer no-transition" loaded="" style="background-color: transparent;"><!--css-build:shady--><img id="img" draggable="false" class="style-scope yt-img-shadow" alt="MrBeast" height="40" width="40" src="https://yt3.ggpht.com/ytc/AMLnZu_NBXmT9J0H9uL94tZm6YxOGdMn0utqYJh1aQlv4A=s88-c-k-c0x00ffffff-no-rj"></yt-img-shadow>
    </a>

I can get the url value of image from src as

https://yt3.ggpht.com/ytc/AMLnZu_NBXmT9J0H9uL94tZm6YxOGdMn0utqYJh1aQlv4A=s88-c-k-c0x00ffffff-no-rj

Could anyone please tell me how to download this image using python ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do it by using urlib.request package

Here, you can simply pass the image URL(from where you want to download and save the image) and directory(where you want to save the download image locally, and give the image name with .jpg or .png) Here I given "local-filename.jpg" replace with this.

Example

import urllib.request
imgURL = "http://site.meishij.net/r/58/25/3568808/a3568808_142682562777944.jpg"

urllib.request.urlretrieve(imgURL, "D:/abc/image/local-filename.jpg")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading