wgetを使っているため、それにパスが通ってないとエラーする。
#! /usr/bin/env python #-*- coding: utf-8 -*- import os import optparse import subprocess def main(): parser = optparse.OptionParser() opts, args = parser.parse_args() args = list(set(args)) if len(args) < 1: parser.error('parameter empty.') cur = os.path.dirname(__file__) os.chdir(cur) with open(os.path.join(cur, 'url.list'), 'a+t') as urllist: alreadies = urllist.readlines() alreadies = map(lambda l: l.strip(), alreadies) not_yet = filter(lambda l: l not in alreadies, args) ignore = filter(lambda l: l in alreadies, args) for ign in ignore: print 'ignore: {0}'.format(ign) url_child = {} for url in not_yet: child = subprocess.Popen(['wget', url]) url_child[url] = child with open(os.path.join(cur, 'url.list'), 'a+t') as urllist: for url, child in url_child.iteritems(): rc = child.wait() if rc == 0: urllist.write(url + os.linesep) else: sys.stderr.write('error: {0} ({1})'.format(url, rc)) if __name__ == '__main__': main()
0 件のコメント:
コメントを投稿