Skip to content

Instantly share code, notes, and snippets.

@dalang
Created May 11, 2013 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalang/5560654 to your computer and use it in GitHub Desktop.
Save dalang/5560654 to your computer and use it in GitHub Desktop.
get nba full teamname from an html file, parse it and print in "key(abb teamname) : value(full teamname)" format get nba teamname from html code from espn.com
#!/usr/bin/perl
open(IFILE, "<fullteamname.html");
open(FILE, ">_ftn.txt");
while(<IFILE>) {
chomp();
if ($_ =~ /<h4>(\w+?)<\/h4>/) {
$sec = $1;
print $sec;
$hash{$sec} = [];
}
if ($_ =~ /espn.go.com\/nba\/team\/_\/name\/(\w{3})\//) {
$team = "'".$1."', ";
}
if ($_ =~ /<h5><a.+?">(.+?)<\/a><\/h5>/) {
print $1;
#$team .= ":'".$1."',";
#$team .= "'"$1."', ";
push($hash{$sec}, $team)
}
}
while (($key, $value) = each %hash) {
print "$key => @{$hash{$key}}\n";
#print @{$value};
syswrite(FILE, "'$key':@{$value}\n");
}
close(FILE);
close(IFILE);
<>
#!/usr/bin/perl
#
use Cwd;
$path = getcwd;
open FILE, 'aaa.txt';
while (<FILE>) {
chomp;
#print "$_\n";
#if ( /<option.*">(.+)<\/option>/ ) {
while (/<option.*?">(.+?)<\/option>/g) {
push @team, $1;
}
}
print "@team";
<>;
#!/usr/bin/perl
#
use Cwd;
$path = getcwd;
open FILE, 'stylesheets/teamlogo.css';
while (<FILE>) {
chomp;
#print "$_\n";
#if ( /<option.*">(.+)<\/option>/ ) {
#while (/<option.*?">(.+?)<\/option>/g) {
while (/nba-large-(\w{3}),/g) {
push @team, "'".$1."',";
}
}
print "@team";
<>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment