#!/usr/bin/perl -w # $Id$ # Ian Glover, ian@manicai.net use strict; use LWP::UserAgent; use HTTP::Request; my $start_day = 2; my $start_month = 3; # Number from zero my $start_year = 1984; my $end_day = 5; my $end_month = 5; my $end_year = 2003; # d for daily, w for weekly, m for monthly. my $period = "d"; my $start = sprintf("%04d%02d%02d", $start_year,($start_month + 1), $start_day); my $end = sprintf("%04d%02d%02d", $end_year,($end_month + 1), $end_day); my $stock; foreach $stock (@ARGV) { my $url = ("http://table.finance.yahoo.com/table.csv" . "?a=" . $start_month . "&b=" . $start_day . "&c=" . $start_year . "&d=" . $end_month . "&e=" . $end_day . "&f=" . $end_year . "&s=" . $stock . "&y=0" . "&g=" . $period . "&ignore=.csv"); print "$url\n"; my $ua = new LWP::UserAgent; $ua->agent("mozilla/4.5"); my $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); if ($response->is_success) { my $file = "$stock-$start-$end.csv"; $file =~ s/\^//gi; open FILE, ">$file" or die "Can't open $file to write"; print FILE $response->content; } }