[Linz-pm] Inline::Perl5 und Mojo::Collections
WFB
wolfgang.banaston at gmail.com
Mon Aug 8 11:06:37 PDT 2016
Hi!
Nachdem ich mich jetzt mit Inline::Perl5 rumspiele, bin ich auch schon auf
das erste Problem gestoßen:
use
v6;
use
LWP::Simple;
use
Mojo::DOM:from<Perl5>;
use
YAML::XS:from<Perl5>;
my $html = LWP::Simple.get('https://metacpan.org/pod/Mojo::DOM');
my $dom =
Mojo::DOM.new($html);
# funzt
say $dom.find('body > div.container-fluid > div:nth-child(2) > div > div >
div.pod.content.anchors > p:nth-child(3)').first.text;
#geht nicht
say $dom.find('body > div.container-fluid > div:nth-child(2) > div > div >
div.pod.content.anchors > p:nth-child(3)').[0].text;
Mein Problem ist das $dom.find. Das gibt ein Mojo::Colection Objekt zurück.
In perl5 greife ich dann mit $dom.find('CSS Selector')->[0] auf das erste
gefundene Element zu, dass dann wieder ein Mojo::DOM Objekt ist. Folgendes
ist also erlaubt:
$dom.find('irgendwas')->[0].find('was anderes')->[0]...
Mit Inline::Perl5 funktioniert das nicht:
$dom.find('irgendwas').[0].find(...) gibt den Fehler:
Mojo::Collection does not have a find method.
Mit .first funktionierts, aber was wenn ich das zweite Element haben will?
Ist die .[0] Syntax falsch?
THX,
Wolf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/linz-pm/attachments/20160808/1da8f24a/attachment.html>
More information about the Linz-pm
mailing list