python - 无法从 Unsplash 网站下载图像
问题描述
各位晚上好
所以我试图从 unsplash 下载所有壁纸图片,从 Firefox 的网络选项卡中获取他们的 API 链接。(它每页只加载 30 个链接,这很好)
编辑:现在我得到了 30 张相同的图像,但我的文件夹中有不同的名称。任何人都可以帮忙:)
这是网络选项卡中的 API 链接:API 网络选项卡链接
这是我的代码:
import json
import pandas as pd
import requests
import os
with open ("Unsplash.json",encoding="UTF-8") as f:
s = json.load(f)
U = pd.json_normalize(s)
U.rename(columns={'alt_description':'Name','urls.raw':'Links'},inplace=True)
Links = U["Links"].tolist()
Name = U["Name"].tolist()
# 1. Works Fine
for Index,l in enumerate(Links):
data = requests.get(l).content
with open ("Unsplash_Pics//" + str(Index) + ".jpg","wb") as f:
f.write(data)
# 2. i get Same image 29 times but with different names :(
for l in Links:
data = requests.get(l).content
for name in Name:
with open ("Unsplash_Pics//" + str(name) + ".jpg","wb") as f:
f.write(data)
解决方案
你试过这个来解决命名问题吗?
for Index,l in enumerate(Links):
data = requests.get(l).content
with open ("Unsplash_Pics//" + str(name[Index]) + ".jpg","wb") as f:
f.write(data)
推荐阅读
- react-native - 添加项目时的竞争条件
- javascript - 一个正则表达式,在单引号或双引号之外用分号分隔
- gwt - 即使在官方教程上也出现 GWT 错误:检查您的模块是否直接或间接继承了“com.google.gwt.core.Core”
- arrays - 传递逗号分隔的键值字典元素并在python中形成一个数组
- php - 从 php 中的嵌套数组中删除一个键
- php - PHP 关联数组 - 将逗号分隔值拆分为单独的数组行
- react-native - [Unhandled promise rejection: Error: Not authorized to use background location services.]
- python - 使用 python 从 GitHub 将口袋妖怪保存到 CSV
- android-emulator - Android studio - apk file
- python - Pyinstaller problem : i created an exe with it but when it fails to be excuted