Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm trying to use HTML::HTML5::Parser to parse some HTML pages I stored in files. My program seems to work just fine except with one file and I'm baffled as to what's happening. My program sits in a loop processing files from a list. I've added debugging so it prints the name of the file and then a dump of the document as parsed and then it goes on to process the document except in this one case. So the relevant bit of code is:

for my $filename (@files) { print "$BASE_DIR$filename\n"; #next if $filename eq '2020-02-17-00:10:01.html'; my $doc = $parser->parse_file($BASE_DIR . $filename); print "doc=", Dumper($doc), $doc->toString;

and the output for the problematic file is:

{my home directory}/met-office-datahub/met-office-forecasts/2020-02-17 +-00:10:01.html doc=$VAR1 = bless( do{\(my $o = '93912432739248')}, 'XML::LibXML::Docu +ment' ); <?xml version="1.0" encoding="windows-1252"?> <html xmlns=""><head/><body/></html> Can't call method "toString" on an undefined value ...

Now I've checked the contents of that file and it actually starts (just like all the others):

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=Edge">

I can't figure out where that strange alleged file contents is coming from or why it affects just that file. In particular the weird <head/> and <body/> tags. I've searched for those strings in my home directory and in /usr/lib/perl5 and done a web search but haven't found anything.

So I'd be very grateful if anybody has any ideas on techniques to figure out what the problem is, or happens to recognize it :)

In reply to HTML::HTML5::Parser weirdness by djh

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2020-11-30 01:57 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found