Yahoo Finance Get Industry and Sector using Perl

This script parses yahoo finance an pulls the Industry and sector for any ticker symbol you pass it. I used it to create a stock screener I am working on. Hope it becomes useful for you.


#!c:\perl\bin\perl.exe
use LWP::Simple;
use LWP::UserAgent;
use HTML::TableExtract;

if ($#ARGV != 0) {
print “$#ARGV usage: need to pass in a symbol\n”;
exit;
}
$sym = $ARGV[0];

my $url = “http://finance.yahoo.com/q/in?s=$sym”;
my $capture = get($url);

$te = HTML::TableExtract->new( depth => 2, count => 0 );
#print “$depth,$i\n”;
$te->parse($capture);
my $table = $te->first_table_found;
foreach $ts ($te->tables) {
#print “Table found at “, join(’,', $ts->coords), “:\n”;
foreach $row ($ts->rows)
{
$a = @$row->[0];
$b = @$row->[1];
print “$a $b\n”;
}
}

About the Author

Greg

Leave a Reply

You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>


Warning: stristr() [function.stristr]: Empty delimiter in /home/thegard5/public_html/gregjessup/wp-content/plugins/wassup/wassup.php on line 2093