Created
March 4, 2010 22:46
-
-
Save adamtaylor/322212 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/perl -w | |
use strict; | |
use WWW::Mechanize; | |
use Data::Dumper; | |
main(); | |
sub main { | |
my $mech = WWW::Mechanize->new(); | |
my $base_url = 'http://uk.finance.yahoo.com'; | |
$mech->get( 'http://uk.finance.yahoo.com/q/cp?s=%5EFTSE' ); | |
if ( $mech->success() ) { | |
my $links = $mech->find_all_links( url_regex => qr/\/q\?s=/i); | |
#die Dumper $links; | |
my $count = 0; | |
foreach my $link (@{$links}) { | |
# die Dumper $link; | |
my $name = $link->url(); | |
$name =~ s/\/q\?s=//; | |
$name =~ s/\./_/; | |
#print STDERR Dumper $name; | |
$mech->get( $link->url_abs() ); | |
if ( $mech->success() ) { | |
my $link = $mech->find_link( text => 'Historical Prices' ); | |
$mech->get( $link->url_abs() ); | |
if ( $mech->success() ) { | |
$link = $mech->find_link( text => 'Download To Spreadsheet' ); | |
$mech->get( $link->url_abs() ); | |
if ( $mech->success() ) { | |
my $filename = '/Users/adam/Desktop/ftse/' . $name . '.csv'; | |
$mech->save_content( $filename ); | |
} | |
} | |
} | |
$count++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment