首页 > 解决方案 > 如何从数据框中的 URL 下载图像并使用存储在数据框中的特定 id 标记集合图像?

问题描述

df我拥有的数据框有列['index', 'en_title', 'jp_title', 'en_description', 'jp_description', 'image_url', 'store_item_id'],我想从列中的 url 下载图像'image url'并用列中的数字标记它们'store_item_id'

截屏

到目前为止,我已经尝试过:

import requests

image_url = list(df["image_url"])

for img in image_url:
    file_name = img.split('/')[-1]
    print("Downloading file:%s"%file_name)
    r = requests.get(img, stream=True)
 # this should be file_name variable instead of "file_name" string 

with open(file_name, 'wb') as f:
    for chunk in r:
        f.write(chunk)

它运行了,但我没有下载任何图像,而且我还没有弄清楚如何用'store_item_id'.

标签: pythonpandasimagefor-loopdownload

解决方案


推荐阅读