根据 Google Books API 文档,每卷产生 6 个不同的图像链接(smallThumbnail、thumbnail、small、medium、large、extraLarge)。
不幸的是,对于我尝试过的所有查询(并且我已经尝试了很多),都smallThumbnail被thumbnail返回了。(示例查询)
另外,除了相当小之外,这两张图片的右下角还有这个小假狗耳朵
他们是否弃用了高质量的图像链接?还有其他方法来获取这些图像吗?我尝试过的其他 API 要么已弃用 (Goodreads),要么不太广泛 (Open Library)
我有一个字典列表,我在搜索 JSON url 时正在填写它。问题是 JSON(由 Google Books API 提供)并不总是完整的。这是对书籍的搜索,据我所知,所有书籍都有 id、标题和作者,但并非所有书籍都有图像链接。以 JSON 链接为例:搜索哈利波特。
请注意,它始终返回 10 个结果,在此示例中,有 10 个 ID、10 个标题、10 个作者,但只有 4 个图像链接。
@app.route('/search', methods=["GET", "POST"])
@login_required
def search():
if request.method == "POST":
while True:
try:
seek = request.form.get("seek")
url = f'https://www.googleapis.com/books/v1/volumes?q={seek}'
response = requests.get(url)
response.raise_for_status()
search = response.json()
seek = search['items']
infobooks = []
for i in range(len(seek)):
infobooks.append({
"book_id": seek[i]['id'],
"thumbnail": seek[i]['volumeInfo']['imageLinks']['thumbnail'],
"title": seek[i]['volumeInfo']['title'],
"authors": seek[i]['volumeInfo']['authors']
})
return render_template("index.html", infobooks=infobooks)
except (requests.RequestException, KeyError, TypeError, ValueError): …Run Code Online (Sandbox Code Playgroud)