code, tests, docs
[catagits/DOM-Tiny.git] / examples / entities.pl
diff --git a/examples/entities.pl b/examples/entities.pl
new file mode 100644 (file)
index 0000000..8b7cba4
--- /dev/null
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use HTTP::Tiny;
+use DOM::Tiny;
+use Encode 'decode';
+
+# Extract named character references from HTML Living Standard
+my $res = HTTP::Tiny->new->get('https://html.spec.whatwg.org');
+my $dom = DOM::Tiny->new(decode 'UTF-8', $res->{content});
+my $rows = $dom->find('#named-character-references-table tbody > tr');
+for my $row ($rows->each) {
+  my $entity     = $row->at('td > code')->text;
+  my $codepoints = $row->children('td')->[1]->text;
+  print "$entity $codepoints\n";
+}
+
+1;