13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

feedparserで自動的にねこ画像を拾ってくる

Posted at

諸事情でねこ画像を大量に集める必要が出てきた時のためのプログラム。
まずはpipでfeedparserをインストール。

$ sudo pip install feedparser

そしてこれが本体。picasaから取ってきてる。

get_cat.py
# -*- coding: utf-8 -*-
import feedparser
import urllib
import os


def download_picture(q, count=10):
    u"""qの画像をcount件 取ってくる。"""
    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)
13
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?