Problème initialisation parser

Problème initialisation parser - Perl - Programmation

Marsh Posté le 08-04-2008 à 14:43:32    

Bonjour à tous,
 
J'ai écrit un programme Perl, pour récupérer un lien dans une balise. Cependant dans ma console après exécution de ce programme, on m'affiche :
 

Code :
  1. Use of uninitialized value in subroutine entry at Essai_1.pl line 66.


 
Voici mon code :  
 

Code :
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use HTML::Parser;
  5. use LWP::Simple;
  6. #Variables
  7. my $baseurl = 'http://www.google.com/';
  8. my $flag = 0;
  9. die "usage: $0 site gene\n"
  10.     if @ARGV != 2;
  11. my $pharmGKB = $ARGV[0];
  12. my $nom_gene = $ARGV[1];
  13. #Page URL où parser
  14. my $url = $baseurl.'search?hl=fr&q='.$pharmGKB.'+'.$nom_gene.'&btnG=Rechercher&meta=';
  15. #print "$url\n";
  16. my $PAGE = get($url);
  17. sub check { defined $_[0] and $_[0] =~ m/$_[1]/ }
  18. #Parser
  19. my $parser = HTML::Parser->new(start_h => [\&start_rtn,"tag, attr"],
  20.                 text_h => [\&text_rtn, "text"],
  21.                 end_h => [\&end_rtn, "tag"]
  22.                 );
  23. sub start_rtn {
  24. my ($tag, $attr) = @_;
  25. if ($tag =~ /^a$/
  26.         and check( $attr->{href}, qr{^http://www.pharmgkb.org/do/serve\?objId=} )
  27.         and check( $attr->{class}, qr{^l$} )
  28.         and check( $attr->{onmousedown}, qr{return clk\(this\.href,'','','res','1',''\)} ) ){   
  29.       $flag = 1;
  30.       my $URL = $attr->{href};
  31.       print "$URL";
  32.    }
  33. }
  34. sub text_rtn {
  35. my ($text) = @_;
  36.    $text =~ s/\n/ /g;
  37. if($flag == 1){               
  38.          print "$text\n";
  39.      }
  40. }
  41. sub end_rtn {
  42. my ($tag) = @_;
  43. if ($tag =~ /^\/a$/ && $flag == 1){
  44.               $flag = 0;
  45. }
  46. }
  47. #start parsing
  48. $parser->parse($PAGE);
  49.  
  50. #end parser
  51. $parser->eof;


La ligne 66 correspond à $parser -> parse($PAGE)
 
Merci pour vos commentaires

Reply

Marsh Posté le 08-04-2008 à 14:43:32   

Reply

Marsh Posté le 08-04-2008 à 15:31:24    

au pif je dirais que $PAGE est vide/nulle


---------------
Software and cathedrals are much the same - first we build them, then we pray.
Reply

Marsh Posté le 08-04-2008 à 15:52:27    

Je ne pense pas, car j'ai même fait un test, pour voir si il récupérait le texte entre les balises <title> et </title>
 
Toujours la même phrase dans la console !!!!
 
Aidez moi, merci

Reply

Marsh Posté le 08-04-2008 à 16:06:48    

ligne 66 avant le $parser->parse($PAGE); tu peux faire un:

Code :
  1. print $PAGE;


Si tu as Data::Dumper installer, fait carrément un Dumer de $PAGE stp!


---------------
Software and cathedrals are much the same - first we build them, then we pray.
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed