我使用它的API从像素下载了一张图片,并将其保存在本地作为.jpg文件.But,问题是windows照片查看器告诉我它不支持这种格式。这是密码,
import urllib.request
import python_pixabay
pix = python_pixabay.Pixabay('4119664-75cc2144f4a944b21e461e646')
# default image search
img_search = pix.image_search()
cis = pix.image_search()
#url to the original image
u = cis['hits'][1]['pageURL']
urllib.request.urlretrieve(u, "local-filename.jpg")发布于 2018-03-18 06:45:20
您不是在下载图像本身。使用urllib.request.urlretrieve(u, "local-filename.jpg"),您可以将u的HTML保存到local-filename.jpg中。如果您检查一下,您可以看到您的URL u看起来像https://pixabay.com/en/flowers-spring-season-nature-3231089/。您需要解析该URL的HTML,找到图像链接并下载图像。您可以使用像Beautiful Soup这样的包来完成这个任务。
https://stackoverflow.com/questions/49344708
复制相似问题