Created
December 8, 2013 12:58
-
-
Save kurehajime/7857109 to your computer and use it in GitHub Desktop.
feedparserで自動的にねこ画像を拾ってくる ref: http://qiita.com/kurehajime/items/dac4b4cca51e52af3152
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo pip install feedparser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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