Skip to content

Instantly share code, notes, and snippets.

@kurehajime
Created December 8, 2013 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurehajime/7857109 to your computer and use it in GitHub Desktop.
Save kurehajime/7857109 to your computer and use it in GitHub Desktop.
feedparserで自動的にねこ画像を拾ってくる ref: http://qiita.com/kurehajime/items/dac4b4cca51e52af3152
$ sudo pip install feedparser
# -*- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment