in reply to Challenge: Parse XML Feed for Youtube channel
(my first steps, I'm sure there is room for improvement)
FWIW: I shortened the input in DATA to two entries to keep it short.
use v5.12; use warnings; use Mojo::DOM; my $data = join "", <DATA>; my $dom = Mojo::DOM->new($data); my $title = $dom->at('title')->text; my $name = $dom->at('name')->text; say <<__HTML__; <h3>$title</h3> <b>$name</b> <ul> @{[ entries() ]} </ul> __HTML__ sub entries { my @res; for my $entry ( $dom->find('entry')->each ) { my $title = $entry->at("title")->text; my $href = $entry->at("link")->attr('href'); my $desc = $entry->at('media\:group > media\:description')->t +ext; push @res, <<__HTML__; <li>[$href|$title]<p> $desc </li> __HTML__ } return @res; }
__DATA__ <feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" xmlns:media=" +http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom"> <link rel="self" href="http://www.youtube.com/feeds/videos.xml?playlis +t_id=PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE"/> <id>yt:playlist:PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE</id> <yt:playlistId>PLA9_Hq3zhoFyOpb-U3DMU7OT93dPUdtpE</yt:playlistId> <yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId> <title>TPC 2022 in Houston</title> <author> <name>Conference in the Cloud! A Perl and Raku Conf</name> <uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri> </author> <published>2022-06-22T19:04:37+00:00</published> <entry> <id>yt:video:waHAGThlRH8</id> <yt:videoId>waHAGThlRH8</yt:videoId> <yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId> <title>Raku -Ofun for Everyone - Daniel Sockwell</title> <link rel="alternate" href="https://www.youtube.com/watch?v=waHAGThlRH +8"/> <author> <name>Conference in the Cloud! A Perl and Raku Conf</name> <uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri> </author> <published>2022-06-24T15:57:38+00:00</published> <updated>2022-06-25T03:36:26+00:00</updated> <media:group> <media:title>Raku -Ofun for Everyone - Daniel Sockwell</media:title> <media:content url="https://www.youtube.com/v/waHAGThlRH8?version=3" t +ype="application/x-shockwave-flash" width="640" height="390"/> <media:thumbnail url="https://i4.ytimg.com/vi/waHAGThlRH8/hqdefault.jp +g" width="480" height="360"/> <media:description>Rakoons like to say that Raku is -Ofun (optimized f +or fun). This talk ... YADDA YADDA ... </media:description> <media:community> <media:starRating count="14" average="5.00" min="1" max="5"/> <media:statistics views="278"/> </media:community> </media:group> </entry> <entry> <id>yt:video:3BYlObnzuKQ</id> <yt:videoId>3BYlObnzuKQ</yt:videoId> <yt:channelId>UC7y4qaRSb5w2O8cCHOsKZDw</yt:channelId> <title>Introducing Perl Data Types - Will Braswell</title> <link rel="alternate" href="https://www.youtube.com/watch?v=3BYlObnzuK +Q"/> <author> <name>Conference in the Cloud! A Perl and Raku Conf</name> <uri>https://www.youtube.com/channel/UC7y4qaRSb5w2O8cCHOsKZDw</uri> </author> <published>2022-06-24T16:00:10+00:00</published> <updated>2022-06-24T16:00:10+00:00</updated> <media:group> <media:title>Introducing Perl Data Types - Will Braswell</media:title> <media:content url="https://www.youtube.com/v/3BYlObnzuKQ?version=3" t +ype="application/x-shockwave-flash" width="640" height="390"/> <media:thumbnail url="https://i4.ytimg.com/vi/3BYlObnzuKQ/hqdefault.jp +g" width="480" height="360"/> <media:description>Data types are hints to a computer language, tellin +g the language’s ... YADDA YADDA ...</media:description> <media:community> <media:starRating count="15" average="5.00" min="1" max="5"/> <media:statistics views="198"/> </media:community> </media:group> </entry> </feed>
<h3>TPC 2022 in Houston</h3> <b>Conference in the Cloud! A Perl and Raku Conf</b> <ul> <li>[https://www.youtube.com/watch?v=waHAGThlRH8|Raku -Ofun for Ev +eryone - Daniel Sockwell]<p> Rakoons like to say that Raku is -Ofun (optimized for fun). Thi +s talk ... YADDA YADDA ... </li> <li>[https://www.youtube.com/watch?v=3BYlObnzuKQ|Introducing Perl +Data Types - Will Braswell]<p> Data types are hints to a computer language, telling the langua +ge’s ... YADDA YADDA ... </li> </ul>
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
shortened description to ... YADDA YADDA ... for line wrap
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Challenge: Parse XML Feed for Youtube channel -- Mojo::DOM
by LanX (Saint) on Jun 29, 2022 at 11:05 UTC |