-1

I want to download image from Flickr using following type of links using Python: https://www.flickr.com/photos/66176388@N00/2172469872/ https://www.flickr.com/photos/clairity/798067744/

This data is obtained from xml file given at https://snap.stanford.edu/data/web-flickr.html

Is there any Python script or way to download images automatically.

Thanks.

user2617042
  • 7
  • 1
  • 4
  • Does this answer your question? [python save image from url](https://stackoverflow.com/questions/30229231/python-save-image-from-url) – Tomerikoo Dec 17 '20 at 21:36
  • https://gist.github.com/yunjey/14e3a069ad2aa3adf72dee93a53117d6 – coderboi Dec 17 '20 at 21:36
  • Thanks @coderboi I tried this technique but it require url with image file extension but I just have flickr url as I have mentioned in question which dos not contain file extension (.jpg, .png, etc). – user2617042 Dec 17 '20 at 23:06
  • Thanks @Tomerikoo, similar to my previous comment, it requires file extension which I do not have. – user2617042 Dec 17 '20 at 23:07

1 Answers1

0

I try to find answer from other sources and compiled the answer as follows:

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')
user2617042
  • 7
  • 1
  • 4