Home > other >  How to download the image using python
How to download the image using python

Time:09-09

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

<a  href="/channel/UCX6OQ3DkcsbYNE6H8uQQuVA">
      <yt-img-shadow fit="" height="40" width="40"  loaded="" style="background-color: transparent;"><!--css-build:shady--><img id="img" draggable="false"  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 ?

CodePudding user response:

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")
  • Related