#!/perl -w
# NAME: camera01.pl
# AIM: Obtain digital camer information from web
# 18/07/2008 geoff mclane http://geoffair.net/mperl
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
require 'logfile.pl' or die "Unable to load logfile.pl ...\n";
require 'htmltools.pl' or die "Unable to load 'htmltools.pl' ...\n";
# log file stuff
my ($LF);
my $pgmname = $0;
if ($pgmname =~ /\w{1}:\\.*/) {
    my @tmpsp = split(/\\/,$pgmname);
    $pgmname = $tmpsp[-1];
}
my $outfile = "temp.$pgmname.txt";
open_log($outfile);
###prt( "$0 ... Hello, World ...\n" );

my $domain = 'http://www.pixmania.com';
my $in_url = $domain.'/fr/fr/1658/xx/150-330/1/1/criteresn_BA00000027.html';
my $out_htm = 'tempcont.htm';
my $out_htm2 = 'tempcont2.htm';
my $rawcnt = 0;
my $trimcnt = 0;
my @lines = ();
my @nlines = ();
my $line = '';
prt( "Doing get [$in_url] ...\n" );
my $content = get( $in_url  ) or mydie( "get FAILED ... $! ...\n" ); 
$rawcnt = length($content);
@lines = split(/\n/,$content);
foreach $line (@lines) {
    chomp $line;
    $line = trim_all($line);
    push(@nlines, $line) if length($line);
}
###$content = trim_all($content);
$content = join("\n",@nlines);
$trimcnt = length($content);
write2file($content, $out_htm);
prt( "Written $trimcnt chars to $out_htm ($rawcnt) ...\n" );
@nlines = array_tags2newline(@nlines);
$content = join("\n",@nlines);
$trimcnt = length($content);
write2file($content, $out_htm2);
prt( "Written $trimcnt chars to $out_htm2 ($rawcnt) ...\n" );
$content = join(' ',@nlines);
my $surtxt = '';
my $subtxt = '';

if ($content =~ /\s+(\d+-\d+\s+sur\s+\d+)\s+/) {
    $surtxt = $1;
    my $ind = index($content,$surtxt);
    $subtxt = substr($content,$ind);
    my $subcnt = 0;
    my $ind2 = index($subtxt,'http://pan.fotovista.com/dev/gui_web/grafx/fleche-violetteD.gif');
    if ($ind2 > 0) {
        $subtxt = substr($content,$ind,$ind2-10);
        $subtxt = removetag($subtxt,'div');
        $subtxt = removetag($subtxt,'span');
        $subtxt =~ s/&nbsp;/ /g;
        while ($subtxt =~ /\s\s/) {
            $subtxt =~ s/\s\s/ /g;
        }
        $subcnt = length($subtxt);
        prt( "Got sur = [$surtxt] ... in $trimcnt characters at offset $ind to $ind2 ... ($subcnt)\n" );
        @lines = split(/\s/,$subtxt);
        write2file(join("\n",@lines), 'tempcont3.txt');
        ##my @hrefs = ret_hrefs_array( $subtxt );
        my @hrefs = collect_hrefs( $subtxt );
        prt( join("\n",@hrefs) );

    }
}
#system( $out_htm );
close_log($outfile,1);
exit(0);

#####################
# eof
