Skip to content

Instantly share code, notes, and snippets.

@adamtaylor
Created March 4, 2010 22:46
Show Gist options
  • Save adamtaylor/322212 to your computer and use it in GitHub Desktop.
Save adamtaylor/322212 to your computer and use it in GitHub Desktop.
#!/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