So I needed a hash of ISO-639 2-letter language codes and their English names. A quick google search turned up this list, and instead of search for a plain text list I decided to use it directly:
use 5.012; use Mojo::UserAgent; use warnings; binmode STDOUT, ':encoding(UTF-8)'; my $ua = Mojo::UserAgent->new(); my $r = $ua->get('http://www.loc.gov/standards/iso639-2/php/code_list. +php'); for my $row ($r->res->dom('tr')->each) { my ($three, $two, $english_name, $french_name) = map $_->text, $row->find('td')->each; say " $two => '$english_name'," if length($two) == 2; } __END__ Output: aa => 'Afar', ab => 'Abkhazian', af => 'Afrikaans', ak => 'Akan', sq => 'Albanian', ...
Only after that I found that use Locales; Locales->new->code2language("qu") does too what I needed.
Thus is the life of the Perl developer: we reinvent stuff because it's just so easy to do.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Webscraping ISO language codes with Mojo
by hossman (Prior) on Mar 27, 2011 at 17:49 UTC |