Skip to content

Instantly share code, notes, and snippets.

@morris555
Created January 13, 2012 13:34
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 morris555/1606192 to your computer and use it in GitHub Desktop.
Save morris555/1606192 to your computer and use it in GitHub Desktop.
#!/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