PDA

View Full Version : Headline grabber help!


-WB0-
09-11-03, 11:01 AM
Have been trying to get the below script to work again. The main function is that it grabs headlines from Yahoo and displays them your site.

Any help would be greatly appreciated.

WB0
---------------------------------------------------- begin code:
#!/usr/bin/perl

$end = $ENV{'QUERY_STRING'};
use LWP::Simple;

$top = qq~
<head>
<meta http-equiv=Cache-Control content=no-cache>
<meta http-equiv=Pragma content=no-cache>
<META http-equiv=PICS-Label content='(PICS-1.1 "http://www.rsac.org/ratingsv01.html" l gen true comment "RSACi North America Server" on "1999.07.26T09:49-0800" for "http://dailynews.yahoo.com" r (n 0 s 0 v 0 l 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://rd.yahoo.com" r (n 0 s 0 v 0 l 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://fullcoverage.yahoo.com" r (n 0 s 0 v 0 l 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://news.yahoo.com" r (n 0 s 0 v 0 l 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://vision.yahoo.com" r (n 0 s 0 v 0 l 0) "http://www.rsac.org/ratingsv01.html" l gen true for "http://search.news.yahoo.com" r (n 0 s 0 v 0 l 0))'>
<base href=http://dailynews.yahoo.com/>
<script language=javascript>
var remote = null;
function rs(n,u,w,h){
remote = window.open(u, n, 'width=' + w + ',height=' + h +',resizable=yes,scrollbars=yes');
if (remote != null) {
if (remote.opener == null)
remote.opener = self;
window.name = 'yahooNewsRoot';
remote.location.href = u;
}
}
</script>
</head>
~;

print "Content-type: text/html\n\n";


#Yahoo Top Stories
if ($end eq "top") {

$html = get("http://dailynews.yahoo.com/");
main();
print "$top$html[0]";
}

#Yahoo Business
elsif ($end eq "bus") {

$html = get("http://dailynews.yahoo.com/h/bs/nm/?u");
business_snapshot();
main2();
print "$top$snap";
print "$html[0]";
}

#Yahoo Entertainment News
elsif ($end eq "ent") {

$html = get("http://dailynews.yahoo.com/h/en/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Technology News
elsif ($end eq "tec") {

$html = get("http://dailynews.yahoo.com/h/tc/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Political News
elsif ($end eq "pol") {

$html = get("http://dailynews.yahoo.com/h/pl/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Sports News
elsif ($end eq "spo") {

$html = get("http://dailynews.yahoo.com/h/sp/ap/?u");
main2();
print "$top$html[0]";
}

#Yahoo World News
elsif ($end eq "wor") {

$html = get("http://dailynews.yahoo.com/h/wl/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Science News
elsif ($end eq "sci") {

$html = get("http://dailynews.yahoo.com/h/sc/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Health News
elsif ($end eq "hea") {

$html = get("http://dailynews.yahoo.com/h/hl/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Oddly Enough
elsif ($end eq "odd") {

$html = get("http://dailynews.yahoo.com/h/od/nm/?u");
main2();
print "$top$html[0]";
}

#Yahoo Crime and Trials
elsif ($end eq "cri") {

$html = get("http://dailynews.yahoo.com/h/cr/ct/?u");
main2();
print "$top$html[0]";
}

#Yahoo Lifestyles
elsif ($end eq "lif") {

$html = get("http://dailynews.yahoo.com/h/lf/nm/?u");
main2();
print "$top$html[0]";
}

else {
print "<font color=red><center><b><h2>Please Check Your SSI Path.<h2></b></center></font>";
}

sub main{
@html = split(/<!-- _JC_ MIDDLE COLUMN -->/,$html);
@html = split(/<!-- _JC_ END MIDDLE COLUMN -->/,$html[1]);
$html[0] =~ s/\">/\" target=\_blank\">/ig;
$html[0] =~ s/bgcolor=dcdcdc/bgcolor=$table_bg/ig;
$html[0] =~ s/window\.location\.replace\(window\.location\)\;//ig;

return $html[0]
}

sub business_snapshot{
@html = split(/<!-- _JC_ MARKET SNAPSHOT -->/,$html);
@html = split(/<!-- _JC_ END MARKET SNAPSHOT -->/,$html[2]);
$html[0] =~ s/bgcolor=\"#ccccff\"/bgcolor=$table_bg/ig;
$snap = $html[0];
return $snap
}

sub main2{
@html = split(/<!-- _JC_ STORIES -->/,$html);
@html = split(/<!-- _JC_ END STORIES -->/,$html[1]);
$html[0] =~ s/.html>/.html target=\_blank>/ig;
$html[0] =~ s/<img src=..*>//ig;
return $html[0]
}

---------------------------------------------------- end code

-WB0-
09-12-03, 10:05 AM
bumping this in hopes someone will answer.

rob2132
09-29-03, 01:24 AM
bumping this in hopes someone will answer.


Exactly what content are you trying to grab? Why is the $top content static? What and how is that supposed to match $end? This script looks like it's doing a lot of unneeded work.