Querying metadata from an HTML page with SPARQL returns nothing

I seem to have a problem using HTML::HTML5::Microdata::Parser or RDF::Query or with the syntax and semantics of SPARQL. I'm interested in this bit from a news site site .

 <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 HTML::HTML5::Microdata::Parser options were just my last attempt to make this work. (I basically have a zero idea of ​​what I'm doing.)

Any ideas how to make this work and get the names of the authors?

+8
html5 perl rdf microdata sparql
source share
1 answer

Just use Mojo :: UserAgent and Mojo :: DOM

 use strict; use warnings; use utf8; use v5.10; BEGIN { binmode *STDOUT, ':utf8'; binmode *STDERR, ':utf8'; } use Mojo::UserAgent; my $url = "http://zpravy.idnes.cz/zacinaji-zapisy-do-prvnich-trid-dn3-/domaci.aspx?c=A160114_171615_domaci_zt"; my $dom = Mojo::UserAgent->new->get($url)->res->dom; # Process all authors for my $span ($dom->find('span[itemprop=author]')->each) { say $span->all_text; } 

Outputs:

 Zdeňka Trachtová san Sabina Netrvalová 

For a short 8-minute lesson on these modules, just watch Mojocast 5 .

+2
source share

All Articles