Catman...::HTML(3pm)

πŸ’– Catmandu::Importer::HTML β€” the HTML importer, bestie edition πŸ’–

okay so welcome to Catmandu::Importer::HTML(3pm), a little gem from the User Contributed Perl Documentation corner of the world 🫢 it's a Catmandu::Importer and it's here to slurp up HTML and turn it into data, no cap. it's giving "glow up for your markup" ✨


🌸 NAME 🌸

Catmandu::Importer::HTML β€” literally just an HTML importer πŸ’… that's the whole vibe, that's the whole job


✨ SYNOPSIS ✨

okay so first, from the command line, like a boss:

# From the command line
$ catmandu convert HTML to YAML < ex/test.html

and then from Perl, which is also iconic:

# From Perl
use Catmandu;

my $importer = Catmandu->importer('HTML',file => 'ex/test.html');

my $n = $importer->each(sub {
    my $hashref = $_[0];
    # ...
});

see that $n? that's how many items you got back. and that # ...? that's where you go feral with the data πŸ¦‹


πŸŽ€ DESCRIPTION πŸŽ€

so this is a Catmandu::Importer whose whole personality is converting HTML data, and it does that using the HTML::TokeParser parser. that's the engine, that's the moment, that's the main character πŸ”₯


πŸ‘‘ CONFIGURATION πŸ‘‘

these are your knobs and dials, bestie. set them, love them, respect them πŸ’œ

  • file β€” read input from a local file, you just give it the path. OR, plot twist, you can pass a scalar reference instead and it'll read from a string 🌈
  • fh β€” read input from an IO::Handle. if you don't specify one, Catmandu::Util::io steps in and creates the input stream for you β€” either from the "file" argument or straight from STDIN πŸ’«
  • encoding β€” the binmode of the input stream fh. it's set to ":utf8" by default, as a treat 🌸
  • fix β€” an ARRAY of one or more fixes or file scripts that get applied to the imported items. yes, an ARRAY. multiple fixes. slay πŸ’…

πŸ¦‹ METHODS πŸ¦‹

every Catmandu::Importer is a Catmandu::Iterable, which means all of its methods are inherited. you don't have to do anything, you just get them. inheritances are the ultimate hand-me-down and honestly? obsessed 😭


πŸ’€ SEE ALSO πŸ’€

go read these next, they're the supporting cast:

  • Catmandu::Importer
  • HTML::TokeParser

real talk though: this page came from perl v5.36.0, dated 2023-02-14, and it lives in the User Contributed Perl Documentation section πŸ’– so go forth, parse that HTML, and be the importer you wish to see in the world πŸŽ€βœ¨πŸ«Ά
πŸ“¦ where this page comes from