简体   繁体   English

使用Flickr API下载图像— Python

[英]Using Flickr API to download images — Python

I was trying to write a python script to download flickr images based on input keyword. 我试图编写一个python脚本来基于输入关键字下载flickr图像。 By accessing the Flickr API I got 2 ways to get images: 通过访问Flickr API,我获得了两种获取图像的方法:

flickr=flickrapi.FlickrAPI(api_key,api_secret,cache=True)

def flickr_walk(keyward):
    photos = flickr.walk(text=keyward,
                         tag_mode='all',
                         tags=keyward,
                         extras='url_c',
                         per_page=100)

    for photo in photos:
        try:
            url=photo.get('url_c')
            print(url)

        except Exception as e:
            print('failed to download image')

Alternatively, 或者,

def flickr_search(keyward):
    obj = flickr.photos.search(text=keyward,
                               tags=keyward,
                               extras='url_c',
                               per_page=5)

    for photo in obj:
        url=photo.get('url_c')
        photos = ET.dump(obj)
        print (photos)

However, either way has some problem: 但是,两种方式都存在一些问题:

  1. some(many) images gathered do not match the "keyward" (eg. input "hand" may result in an image of mountain). 收集的某些(许多)图像与“按键”不匹配(例如,输入“手”可能会产生山峰的图像)。 Searching results are not "accurate". 搜索结果不准确。

  2. it seems like the image download has an maximum limited( per_page has max value 500). 似乎图像下载具有最大限制( per_page的最大值为500)。 But I want to download images as many as possible. 但是我想下载尽可能多的图像。

Could anyone help me out how to fix my problems? 谁能帮助我解决问题? Many thanks. 非常感谢。

I solved the first problem by adding: 我通过添加以下内容解决了第一个问题:

sort="relevance"

in the arguments. 在参数中。 Now the result images are much more relevant to the keywords. 现在,结果图像与关键字更加相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM