【问题标题】:How to download Flickr images using photos url (does not contain .jpg, .png, etc.) using Python如何使用 Python 下载使用照片 url(不包含 .jpg、.png 等)的 Flickr 图片
【发布时间】:2020-12-17 21:34:20
【问题描述】:

我想使用 Python 使用以下类型的链接从 Flickr 下载图像: https://www.flickr.com/photos/66176388@N00/2172469872/ https://www.flickr.com/photos/clairity/798067744/

这个数据是从https://snap.stanford.edu/data/web-flickr.html给出的xml文件中获得的

是否有任何 Python 脚本或方法可以自动下载图像。

谢谢。

【问题讨论】:

  • 这能回答你的问题吗? python save image from url
  • 谢谢@coderboi 我尝试了这种技术,但它需要带有图像文件扩展名的 url 但我只有 flickr url,正如我在问题中提到的那样,它不包含文件扩展名(.jpg、.png 等) .
  • 感谢@Tomerikoo,与我之前的评论类似,它需要我没有的文件扩展名。

标签: python flickr


【解决方案1】:

我尝试从其他来源寻找答案并将答案编译如下:

import re
from urllib import request
def download(url, save_name):
    html = request.urlopen(url).read()
    html=html.decode('utf-8')
    img_url = re.findall(r'https:[^" \\:]*_b\.jpg', html)[0]
    print(img_url)

    with open(save_name, "wb") as fp:
        fp.write(request.urlopen(img_url).read())

download('https://www.flickr.com/photos/clairity/798067744/sizes/l/', 'image.jpg')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多