Search code examples
perldommojolicious

Mojo::DOM: Do some characters need special escaping?


Why does media:group not work though it occurs in the dom?

#!/usr/bin/env perl
use warnings;
use 5.12.0;
use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new();

my $id = 'E7511681ABEA8635';
my $url = 'http://gdata.youtube.com/feeds/api/playlists/' . $id . '?v=2';
my $tx = $ua->get( $url );

say $tx->res->dom->at( 'category' )->type;
say $tx->res->dom->at( 'media:group' )->type;

# category
# Can't call method "type" on an undefined value at ./perl.pl line 13

Solution

  • Because media: is the namespace? if you change the last line to at('group') it returns 'media:group'