WebService::CIA::Parser(3pm)

WebService::CIA::Parser3pm

Parse pages from the cia world factbook

Usage

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

Overview

WebService::CIA::Parser takes a string of HTML and parses it. It will only give sensible output if the string is the HTML for a page whose URL matches "https://www.cia.gov/library/publications/the-world-factbook/print/[a-z]{2}\.html"

This parsing is somewhat fragile, since it assumes a certain page structure. It'll work just as long as the CIA don't choose to alter their pages.

Methods

"new"

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

"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.

It also creates four extra fields: "URL", "URL - Print", "URL - Flag", and "URL - Map" which are the URLs of the country's Factbook page, the printable version of that page, a GIF map of the country, and a GIF flag of the country respectively.

Examples

  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"};

Releases

9 releases since Debian 5.0 (Lenny); the text changed 4 times.

  1. 5.0–7
  2. 8
  3. 9–10
  4. 11
  5. 12–13

Author

Ian Malpass ([email protected])

From libwebservice-cia-perl 1.4-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.