[Python] How to download product images by SKU from a website using Python?

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have an Excel (or CSV) file with a list of product SKUs (like 1806B, 1911B, HR2470, etc.), and I would like to write a Python script that does the following:

    1. Use each SKU to search for the product page on a specific website (for example: makita.hu).
    2. Find and extract the main product image from that page.
    3. Download the image and save it to a local folder as a .webp file.
    4. The filename should be the SKU itself (e.g. 1806B.webp).

    The product pages might follow a pattern like: https://www.makita.hu/?termek=1806B or require a search on the site.

    What did I try?


    I tried using Python with the requests and BeautifulSoup libraries to load the product page using the SKU (for example: 1806B), and then locate the <img> tag that contains the product image.

    Here's my basic attempt:

    import requests
    from bs4 import BeautifulSoup

    sku = "1806B"
    url = f"https://www.makita.hu/?termek={sku}" # Not sure if this is the correct URL pattern
    response = requests.get(url)
    soup = BeautifulSoup(response.content, "html.parser")

    img = soup.find("img")
    print(img["src"])

    Continue reading...

Compartilhe esta Página