Created
January 13, 2012 13:34
-
-
Save morris555/1606192 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
import sys | |
import os | |
import BeautifulSoup | |
import urllib | |
def search(url): | |
bsoup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url)) | |
img = bsoup.findAll("img", {"class": "pict"}) | |
title = str(bsoup.findAll("title")[0]) | |
title = title.split("-")[0].split(":")[1] | |
return img, title | |
def main(): | |
if len(sys.argv) >= 2: | |
img, title = search(sys.argv[1]) | |
os.mkdir(title) | |
for i in range(len(img)): | |
imgurl = img[i].get("src") | |
urllib.urlretrieve(imgurl, "{0}/{1}.jpg".format(title, i)) | |
else: | |
print(u"使用法が正しくありません。") | |
sys.exit() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment