Created
May 11, 2013 17:15
-
-
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
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 | |
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); | |
<> |
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 | |
# | |
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"; | |
<>; |
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 | |
# | |
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