WebSer...:Parser(3pm)

πŸ“¦
version 1.4 Β· 2 versions
  • 1.4 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.4 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ WebService::CIA::Parser ✨

okay bestie, so this is WebService::CIA::Parser, a Perl module from the User Contributed Perl Documentation section (that's the 3pm vibe, iykyk) πŸ’– and it does exactly one thing but it does it so well: it parses pages from the CIA World Factbook πŸ¦‹


🌸 SYNOPSIS 🌸

use WebService::CIA::Parser;
my $parser = WebService::CIA::Parser->new;
my $data = $parser->parse($string);

three lines. that's the whole entrance. she's lowkey iconic for that πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

So WebService::CIA::Parser takes a string of HTML and parses it. that's the job. that's the whole job. 🫢

⚠️ but bestie, listen β€” it will only give sensible output if the string is the HTML for a page whose URL matches this exact thing:
https://www.cia.gov/library/publications/the-world-factbook/print/[a-z]{2}\.html

fr fr, no cap.

Also she's gonna be honest with you: this parsing is somewhat fragile 😭 because it assumes a certain page structure. It'll work just as long as the CIA don't choose to alter their pages. so like... as long as nobody touches anything, we're slaying. the second they redesign? we're cooked. πŸ’€


πŸ‘‘ METHODS πŸ‘‘

✨ new ✨

Creates a new WebService::CIA::Parser object. It takes no arguments.

she's low maintenance. no arguments, no drama, no emotional baggage. just vibes. 🧚

✨ parse($html) ✨

Parses a string of HTML take from the CIA World Factbook. It takes a single string as its argument and returns a hashref of fields and values. πŸ“

The values are stripped of all HTML. <br> tags are replaced by newlines. (yes bestie, the <br> tags get turned into actual newlines, we love a clean glow-up ✨)

It also creates four extra fields, and these are the little bonus besties:

  • URL β€” the URL of the country's Factbook page
  • URL - Print β€” the URL of the printable version of that page
  • URL - Flag β€” a GIF flag of the country
  • URL - Map β€” a GIF map of the country

four freebies. we love to see it. πŸ’œ


🌈 EXAMPLE 🌈

okay so here's the whole thing in action, main character energy only:

use WebService::CIA::Parser;
use LWP::Simple qw(get);

$html = get(
  "https://www.cia.gov/library/publications/the-world-factbook/print/uk.html"
);
$parser = WebService::CIA::Parser->new;
$data = $parser->parse($html);
print $data->{"Population"};

grab the UK page, parse it, print the Population field. that's it. she ate and left no crumbs. πŸ”₯


πŸ’– AUTHOR πŸ’–

Ian Malpass (ian-cpan@indecorous.com)


Copyright 2003-2007, Ian Malpass

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The CIA World Factbook's copyright information page (https://www.cia.gov/library/publications/the-world-factbook/docs/contributor_copyright.html) states:

The Factbook is in the public domain. Accordingly, it may be copied
freely without permission of the Central Intelligence Agency (CIA).

public domain bestie!! copy away, no permission needed, the CIA said so themselves 😌


πŸ¦‹ SEE ALSO πŸ¦‹

  • WebService::CIA

and that's the whole page, babe πŸ’… this was the WebSer...:Parser(3pm) manual page, perl v5.34.0, dated 2022-06-28 β€” go forth and parse those factbook pages, and remember: as long as nobody redesigns the website, you're golden. mwah 🫢✨