WebSer...:Parser(3pm)
β¨ 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 pageURL - Printβ the URL of the printable version of that pageURL - Flagβ a GIF flag of the countryURL - 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 π
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 π«Άβ¨
π¦ where this page comes from
- debian bookworm: libwebservice-cia-perl 1.4-4
- debian trixie: libwebservice-cia-perl 1.4-4
- ubuntu noble: libwebservice-cia-perl 1.4-4
- ubuntu resolute: libwebservice-cia-perl 1.4-4
- ubuntu stonking: libwebservice-cia-perl 1.4-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms