Use Python to invoke the Flickr API to fetch image data

Source: Internet
Author: User

Flickr is Yahoo's image sharing website, which has a lot of wonderful pictures shared by netizens all over the world, and is considered a professional picture website. Its API is also friendly and can be implemented in a variety of functions. Here I used Python to invoke its API to get a lot of photo data.

First you need to go to Flickr to register as its developer, create apps, get Api_key and Api_secret, and its API URL in: https://www.flickr.com/services/api/

Flickr offers a variety of development tools to use. Here we use Python development tools. The official recommended development tool is the BEEJ's Python Flickr API. Https://stuvel.eu/flickrapi

Can be installed directly using the PIP installation tool, the input FLICKRAPI can be installed automatically.

Official documentation is here: https://stuvel.eu/flickrapi-doc/

The best way to crawl your photo data is to use its walk method. This method essentially calls the Flickr.photos.search interface, and various parameters can be found in the API description: https://www.flickr.com/services/api/flickr.photos.search.html

With this method, input different parameters, you can meet most of the data mining needs, including time, location, photo type.

A simple code is posted here for reference only:

1 #Coding:utf-82 ImportFlickrapi3 #enter the key and secret for the API4Flickr=Flickrapi. Flickrapi (Api_key,api_secret)5 Try:6     #crawl the text for ' New York ' photos, where you can set other parameters according to your needs7Photos=flickr.walk (text='New York', extras='Url_c')8 excepte:9     Print('Error')Ten  forPhotoinchPhotos: One     #get the URL of the photo, set the size to Url_c (see FLICKRAPI official documentation for specific parameters) AUrl=photo.get ('Url_c') -     Print(str (URL))

It is important to note that, in the event of a loop, it is possible that the amount of data is too large, so you need to add some restrictions, such as a call to only call data over a period of time, and then batch mining data.

Use Python to invoke the Flickr API to fetch image data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.