BeautifulSoupとwgetを組み合わせた自動ダウンロードスクリプト

#! /usr/bin/env python                                                                
# -*- coding:utf-8 -*-                                                                

from bs4 import BeautifulSoup
import urllib2
import os

url = "http://caseyscaverns.com/4/halloween5.html"
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
contents = soup.findAll("a")
for content in contents:
    link = content.get("href")
    if not ".mid" in link:
        if not ".wav" in link:
            continue
    #print link
    os.system("wget "+link)