| px | top | add code | search | signup | login | help |
#############################################
# This is the PERL code for getSP100data.pl #
# ver 0.0.1 #
# 20020904 #
#############################################
#!/usr/bin/perl
use lib qw( ..);
use HTML::TableExtract;
use LWP::Simple;
use Data::Dumper;
my $te = new HTML::TableExtract( depth=>2, count=>3, gridmap=>0);
my $content = get("http://www.spglobal.com/indexmain100_data.html");
$te->parse($content);
foreach $ts ($te->table_states) {
foreach $row ($ts->rows) {
# Use '::' as a delimiter since some of the company names have a ',' in them
$cdata = join('::', @$row);
$cdata =~ s/\s{2,}/ /;
$cdata =~ s/\s{2,}/ /;
print $cdata,'::';
# print Dumper @$row;
# print Dumper $row if (scalar(@$row) == 2);
}
}
#############################################
# End PERL Code #
#############################################
/*********************************************/
/* This is the PHP code for getSP100data.php */
/* ver 0.0.1 */
/* 20020904 */
/*********************************************/
<?php
$data = `./getSP100data.pl`;
$arrData = explode("::", $data);
foreach($arrData as $key=>$val) {
if ($key % 2 == 0) {
// As of 20020904 Nasdaq used a "/" character instead of a "."
// to delimit class A stocks from class B stocks
$keyname = preg_replace('/\./i','/',$val);
} else {
$arrFinal[$keyname] = $val;
}
}
ksort ($arrFinal);
reset ($arrFinal);
while (list ($key, $val) = each ($arrFinal)) {
echo "$key = $val<br>";
}
?>
/*********************************************/
/* END PHP Code */
/*********************************************/
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.