By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Perl HTML Parser does not work

P: 10
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
Share this Question
Share on Google+
5 Replies


P: 10
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 2.5K+
P: 4,059
See where my finger is pointing? That is where you are making a mistake.
Aug 23 '08 #3

eWish
Expert 100+
P: 971
Showing use the code would result in KevinADC not having to use his fingers.

--Kevin
Aug 24 '08 #4

P: 10
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

P: 10
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.