下载没有扩展名的图像

Downloading Image with no Extension

我搜索了很多,但没有找到关于如何使用 BeautifulSoup 和 urllib 来使用 src link 并在没有扩展名的情况下下载图像的好答案,因为例如,Facebook 应用程序图标的图像@ https://play.google.com/store/apps/details?id=com.facebook.katana is https://lh3.googleusercontent.com/ZZPdzvlpK9r_Df9C3M7j1rNRi7hhHRvPhlklJ3lfi5jk86Jd1s0Y5wcQ1QgbVaAP5Q=w300-rw - 没有扩展名。

我应该使用什么库或方法来下载此类图像?

您可以通过使用 class 名称和 src 属性的 img 标签获取图像:

import requests
import urllib
r = requests.get("https://play.google.com/store/apps/details?id=com.facebook.katana")
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.content)

img = soup.find("img",{"class":"cover-image"})["src"]
urllib.urlretrieve(img,"fb.jpg")