A
alfonsobaldaserra
hello
i am trying to write a script which will go to bbc's top 40 pages and
show only intended contents.
i have written a script
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $res = $ua->get("http://www.bbc.co.uk/radio1/chart/singles");
if ($res->is_success) {
open my $bbc, ">", "bbc.txt" or die "$!\n";
print $bbc $res->decoded_content;
close $bbc;
} else {
die "could not fetch bbc.co.uk\n";
}
open my $bbc, "<", "bbc.txt";
while (<$bbc>) {
print if m!<span class="artist">(.*)</span>!;
print if m!<span class="track">(.*)</span>!;
#next unless $_ =~ m[(<span class="artist">)|(<span
class="track">)];
#my ($foo) =~ m!<span class="artist">(.*)</span>!;
#my ($bar) =~ m!<span class="track">(.*)</span>!;
# print "$foo -> $bar\n";
}
__RESULT__
<span class="artist">Tinie Tempah</span>
<span class="track">Written In The Stars</span>
<span class="artist">Bruno Mars</span>
<span class="track">Just The Way You Are (Amazing)</span>
<span class="artist">Labrinth</span>
<span class="track">Let The Sun Shine</span>
<span class="artist">Adele</span>
<span class="track">Make You Feel My Love</span>
<span class="artist">Taio Cruz</span>
<span class="track">Dynamite</span>
but i can't figure out
#1 how to parse $res->decoded_content without writing it to a file
because apparently the whole page is a single string
#2 how to show data in artist - track format, like
Tinie Tempah - Written In The Stars
#3 how to make this work
#next unless $_ =~ m[(<span class="artist">)|(<span
class="track">)];
#my ($foo) =~ m!<span class="artist">(.*)</span>!;
#my ($bar) =~ m!<span class="track">(.*)</span>!;
# print "$foo -> $bar\n"
appreciate your time gents.
salute
i am trying to write a script which will go to bbc's top 40 pages and
show only intended contents.
i have written a script
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $res = $ua->get("http://www.bbc.co.uk/radio1/chart/singles");
if ($res->is_success) {
open my $bbc, ">", "bbc.txt" or die "$!\n";
print $bbc $res->decoded_content;
close $bbc;
} else {
die "could not fetch bbc.co.uk\n";
}
open my $bbc, "<", "bbc.txt";
while (<$bbc>) {
print if m!<span class="artist">(.*)</span>!;
print if m!<span class="track">(.*)</span>!;
#next unless $_ =~ m[(<span class="artist">)|(<span
class="track">)];
#my ($foo) =~ m!<span class="artist">(.*)</span>!;
#my ($bar) =~ m!<span class="track">(.*)</span>!;
# print "$foo -> $bar\n";
}
__RESULT__
<span class="artist">Tinie Tempah</span>
<span class="track">Written In The Stars</span>
<span class="artist">Bruno Mars</span>
<span class="track">Just The Way You Are (Amazing)</span>
<span class="artist">Labrinth</span>
<span class="track">Let The Sun Shine</span>
<span class="artist">Adele</span>
<span class="track">Make You Feel My Love</span>
<span class="artist">Taio Cruz</span>
<span class="track">Dynamite</span>
but i can't figure out
#1 how to parse $res->decoded_content without writing it to a file
because apparently the whole page is a single string
#2 how to show data in artist - track format, like
Tinie Tempah - Written In The Stars
#3 how to make this work
#next unless $_ =~ m[(<span class="artist">)|(<span
class="track">)];
#my ($foo) =~ m!<span class="artist">(.*)</span>!;
#my ($bar) =~ m!<span class="track">(.*)</span>!;
# print "$foo -> $bar\n"
appreciate your time gents.
salute