Help editing a small script...

They have: 32 posts

Joined: Jun 1999

Ok, usally a small script like this wouldn't take long for me to customize, but this one seems to have stumped me. It takes certain content from one page, and prints it to another. The script it: (Directly copied from their site [url=http://www.go2cgi.com/free/download.pl?s=abcnews):]http://www.go2cgi.com/free/download.pl?s=abcnews):[/url]

#!/usr/local/bin/perl
#########################################################
# #
# ABCNews Retriever #
# #
#########################################################
# #
# abcnews.pl #
# #
# This script will fetch the World News from the #
# ABCNews Website and display it on your Website. #
# #
# To install this script simply upload it to your #
# CGI-BIN and CHMOD it 755. #
# #
# On any page where you want the ABCNews World News #
# to be displayed put this SSI call: #
# <!--#include virtual="cgi-bin/abcnews.pl"--> #
# #
# If you have any further questions, direct them to #
# the support forum at http://www.go2cgi.com/ #
# #
#########################################################

# Nothing in this script needs editing

# Change nothing below this line
#########################################################

print "Content-type: text/html\n\n";
use LWP::Simple;
$doc = get "http://abcnews.go.com/";;
@abc=split(/\n/,$doc);
$rcd=0;
$news="";
foreach $line (@abc){
$ft=substr "$line","",7;
if($rcd==1){
if($line!~/font/){
if($ft ne '<!-- Wo'){
$news="$news\n<tr><td valign=top><font size=-1>•</font></td><td valign=top>$line</td></tr>";
}
}else{
if($line!~/<\/font>/){
$news="$news\n$line";
}
}
}
if ($ft eq '<B>W O '){
$rcd=1;
}elsif($ft eq '</font>'){
$rcd=0;
}
}
print "<table border=0 cellpadding=0 cellspacing=2>\n";
$news=~s/html\">/html\"><font size=-1>/gi;
$news=~s/<\/a>/<\/a><\/font>/gi;
print "$news</td></tr>";
print "<tr><td colspan=2></td></tr><tr><td colspan=2><p><center><font size=-2>Today's World News Provided by</font><br><a href=http://abcnews.go.com/><u><font color=blue size=-2>ABC</font><font color=black size=-2>NEWS.com</font></u></a><font size=-2> and the </font><a href=\"http://www.go2cgi.com/\"><u><font color=blue size=-2>ABC</font><font color=black size=-2>NEWS Retriever</font></u></a></center></p></td></tr>\n";
print "</table>\n";

##############################

The major prob is there is no documentation, and it is made just for abcnews.com .

I need to edit it so it'll grab content from http://www.kcc.net/hcs/homework.htm#9 (The grade 9 section. Nothing above or below it).

A sample of it running can be found at http://www.go2cgi.com/free/abcnews.html .

Any help would be appreciated.

-steve

They have: 99 posts

Joined: May 1999

Set a flag variable up to check for the begining of the section you wish to import(I have inserted text to look for a link tag=9):

Outside the foreach block set $start=0;$end=0;

Then just inside the foreach block set the test

if($line=~/<A NAME="9">/){
$start=1;
}

Then set a flag variable up to check for whatever denotes the end of your data section -or- what denotes the start of the next (I have inserted a link tag for grade 10)

if($line=~/<A NAME="10">/){
$end=1;
}
Then just set a control if block within the foreach block
if($start && !$end){
....
The rest of the foreach block here
....
}

Now just change the URL variable to
$doc=get "http://www.kcc.net/hcs/homework.htm";;

and clean up the footer.

Tazman

They have: 32 posts

Joined: Jun 1999

Umm, could you explain it a little better. I'm not that good at CGI.

-steve

They have: 32 posts

Joined: Jun 1999

Please...

They have: 850 posts

Joined: Jul 1999

Ok, here is the code you need

code:

#!/usr/bin/perl 
use LWP::Simple;
$html = get("http://www.kcc.net/hcs/homework.htm");

while($html =~ m/Grade 9 Homework<\/font><\/b><\/td>\s+<\/tr>(.+?)<td width="18%" bgcolor="#008000" align="center">/sogi)
{
	$grade9 = "<table border=\"1\" width=\"100%\">$1<\/table>";

}

print "Content-type:text/html\n\n";
print $grade9;
[/code]

An example of it can be viewed at  http://dlo.net/~rob/cgi-bin/grade9.cgi 

To use it on your page if you have SSI you can go

<!--#exec cgi="/cgi-bin/grade9.cgi"-->



------------------
Termites eat through wood two times faster when listening to rock music. 

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.