Hi Customer (name blocked for privacy), thanks for the question. I hope this code will help you. Save it for example in a file called "fetch.pl" and start it using the comand line: "perl fetch.pl" or even only "fetch.pl" (depening on your system)
#-----------------------START OF CODE
#!/usr/bin/perl -w
use strict;
package HTMLStrip;
use base "HTML::Parser";
use LWP::Simple;
# here you define the file that the program will write the output into
open(DATA, ">output.txt");
my $pre_flag = 0;
my $html ="";
#used to react to the tags that the wiki uses for the code start
sub start {
my ($self, $tag, $attr, $attrseq, $origtext) = @_;
if ($tag =~ /^pre$/i) {
# set if we find the tag
$pre_flag=1;
}
}
#all within the pre tags will simply be written to file
sub text {
my ($self, $text) = @_;
if ($pre_flag==1) {
print $text; #(for debug purposes i write the output to console as well)
print DATA $text; #write the data to file
}
}
#used to react to the tags that the wiki uses for the code start
sub end {
my ($self, $tag, $origtext) = @_;
# reset appropriate flag if we find the tag
if ($tag =~ /^pre$/i) { $pre_flag = 0; }
}
my $p = new HTMLStrip;
#load the whole html page
$html = get("http://www.financialmathematics.com/wiki/index.php/Matlab_example_with_dependency.m");
#parse the page
$p->parse($html);
#close the file
close(DATA);
#------------------ END OF CODE -----------------
Edited by Kerim on March 15 2007 at 4:49 AM
1 Other Expert Agrees with this!