0

I am trying to fill an excel sheet with images (jpeg). For these images I have a list of src's that were retireved from the Shopify API. I am wondering how I can extract these images from the src and place them in a dataframe and then upload to excel.

productDF = pd.DataFrame(columns=('ProductID','Title','Store Image'))
count = 0

for prod in all_products['products']:
    try:           
        productDF.loc[count] = (prod['id'], prod['title'],prod['images'][0]['src'])
    except:
        productDF.loc[count] = (prod['id'], prod['title'],"no image")
    count+=1

productDF.to_excel('products.xlsx')

This is my for loop which gets the src for each product, but I need some help working out how I would get the actual image.

Chris
  • 5
  • 1
  • Can you give an example to tell us what exactly `prod['images'][0]['src']` contains? – mss Oct 24 '22 at 12:27
  • Sorry shouldve added this: – Chris Oct 24 '22 at 12:29
  • {'id': 36707157246183, 'product_id': 7525946786023, 'position': 1, 'created_at': '2022-01-28T15:32:22+00:00', 'updated_at': '2022-01-28T15:32:22+00:00', 'alt': None, 'width': 1831, 'height': 2300, 'src': 'https://cdn.shopify.com/s/files/1/0556/8518/5721/products/image_67faaaea-c85f-4d6b-9d00-1a5ec7c72e4c.jpg?v=1643383942', 'variant_ids': [], 'admin_graphql_api_id': 'gid://shopify/ProductImage/36707157246183'} – Chris Oct 24 '22 at 12:29
  • This question might be of relevance: https://stackoverflow.com/questions/30229231/python-save-image-from-url/30229298 – mss Oct 24 '22 at 12:33

0 Answers0