467,146 Members | 1,006 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

Perl HTML Parser does not work

Hi!

If I want to parse this html file (e.g. copy it into an other file using HTML Parser) I only get an empty file.
What am I doing wrong?
Thank you for your answer in advance.

Gábor
Aug 23 '08 #1
  • viewed: 2051
Share:
5 Replies
I forgot to mention that if I am working with a much simpler file e.g. an HTML file that has only 5 or 6 rows then everything is fine.

Gábor
Aug 23 '08 #2
KevinADC
Expert 2GB
See where my finger is pointing? That is where you are making a mistake.
Aug 23 '08 #3
eWish
Expert 512MB
Showing use the code would result in KevinADC not having to use his fingers.

--Kevin
Aug 24 '08 #4
Hello,

This is the code I used:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3.  use strict;
  4.  
  5.  
  6.  # define the subclass
  7.  package IdentityParse;
  8.  use base "HTML::Parser";
  9.  
  10.  open(OUT,">placid.html");
  11.  
  12.  sub text {
  13.      my ($self, $text) = @_;
  14.      # just print out the original text
  15.      print OUT $text;
  16.  }
  17.  
  18.  #sub comment {
  19.   #   my ($self, $comment) = @_;
  20.    #  # print out original text with comment marker
  21.     # print OUT "";
  22. # }
  23.  
  24.  sub start {
  25.      my ($self, $tag, $attr, $attrseq, $origtext) = @_;
  26.      # print out original text
  27.      print OUT $origtext;
  28.  }
  29.  
  30.  sub end {
  31.      my ($self, $tag, $origtext) = @_;
  32.      # print out original text
  33.      print OUT $origtext;
  34.  }
  35.  my $p = new IdentityParse;
  36.  $p->parse_file("index.html");
  37.  
Thank you for your help in advance:

Gábor
Aug 24 '08 #5
Hello Guys,

It was all my mistake. The file's name I wanted to parse was x.htm and not x.html.
Sorry for bothering the forum.
I am new to perl I thought that there is a much complex problem.
Sorry again.

Gábor
Aug 24 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

42 posts views Thread by Fred Ma | last post: by
2 posts views Thread by Neal | last post: by
13 posts views Thread by Jesse Thompson | last post: by
2 posts views Thread by zzapper | last post: by
5 posts views Thread by Bob MacBob | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.