Feedparser automatically picks up cat images

A program for when it becomes necessary to collect a large number of cat images for various reasons. First, install feed parser with pip.

$ sudo pip install feedparser

And this is the main body. I'm getting it from picasa.

get_cat.py


# -*- coding: utf-8 -*-
import feedparser
import urllib
import os


def download_picture(q, count=10):
    u"""Fetch count images of q."""
    count = str(count)
    feed = feedparser.parse("https://picasaweb.google.com/data/feed/base/all?q=" + q + "&max-results=" + count)
    pic_urls = []
    for entry in feed['entries']:
        url = entry.content[0].src
        if not os.path.exists(os.path.join(os.path.dirname(__file__), q)):
            os.mkdir(os.path.join(os.path.dirname(__file__), q))
        urllib.urlretrieve(url, os.path.join(os.path.dirname(__file__), q, os.path.basename(url)))
        print('download:' + url)

if __name__ == "__main__":
    download_picture("cat", 10)

Recommended Posts

Feedparser automatically picks up cat images
Categorize cat images using ChainerCV