I seem to be having some issue either using HTML::HTML5::Microdata::Parser
or RDF::Query
or with SPARQL syntax and semantics. I am interested in this bit from a news site page.
<div class="authors">
Autoři: <span itemprop="author" itemscope itemtype="http://schema.org/Person"><a rel="author" itemprop="url" class="name" href="http://vice.idnes.cz/novinari.aspx?idnov=2504" ><span itemprop="name">Zdeňka Trachtová</span></a></span>
,
<span itemprop="author" itemscope itemtype="http://schema.org/Person"><a rel="author" itemprop="url" href="http://vice.idnes.cz/novinari.aspx?idnov=3495" ><span itemprop="additionalName">san</span></a><span class="h" itemprop="name">Sabina Netrvalová</span></span>
</div>
Here is my test code:
#! env perl
use strict;
use Data::Dumper;
use HTML::HTML5::Microdata::Parser;
use RDF::Query;
use IO::Handle;
use LWP::Simple;
STDOUT->binmode(":utf8");
STDERR->binmode(":utf8");
my $htmldoc = LWP::Simple::get(
"http://zpravy.idnes.cz/zacinaji-zapisy-do-prvnich-trid-dn3-/domaci.aspx?c=A160114_171615_domaci_zt");
die "Could not fetch URL. $@" unless defined $htmldoc;
my $microdata = HTML::HTML5::Microdata::Parser->new (
$htmldoc, $ARGV[0],
{auto_config => 1, tdb_service => 1, xhtml_meta => 1, xhtml_rel => 1});
print STDERR "microdata->graph:\n", Dumper($microdata->graph), "\n";
my $query = RDF::Query->new(<<'SPARQL');
PREFIX schema: <http://schema.org/>
SELECT *
WHERE {
?author a schema:Person .
}
SPARQL
my $people = $query->execute($microdata->graph);
print STDERR "authors from RDF:\n", Dumper($people), "\n";
while (my $person = $people->next) {
print STDERR "people: ", $person, "\n";
}
The options to the HTML::HTML5::Microdata::Parser
were just my last ditch effort to make this work. (I have basically zero idea what I am doing.)
Any ideas how to make this work and get the authors' names?
HTML::Microdata
instead. It works for what I want to do with it. However, I am still interested in hearing about how to make theHTML::HTML5::Microdata::Parser
plus SPARQL way work. – Dys