Photobucket에서 RSS 피드를 읽고 구문 분석하려고하는데 요소의 하위 요소를 얻는 데 어려움을 겪고 있습니다. 다음은 샘플 RSS XML입니다.Perl을 사용하여 Photobucket RSS 피드를 파싱 하시겠습니까?
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>BlahBlah's Photobucket websitePic album media</title>
<description>A feed of BlahBlah's images and videos for this album</description>
<pubDate>Sun, 7 Aug 2011 20:11:31 MDT</pubDate>
<link>http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?sort=ascending</link>
<lastBuildDate>Mon, 13 Feb 2012 21:04:43 MST</lastBuildDate>
<generator>Photobucket feed generator</generator>
<language>en-us</language>
<ttl>60</ttl>
<item>
<title>F1 sidecar</title>
<link>http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view&current=IMG_0673.jpg&sort=ascending</link>
<dc:creator>BlahBlah</dc:creator>
<description><p><a href="http://s1100.photobucket.com/albums/g409/BlahBlah/">BlahBlah</a> posted a photo</a></p><p><a href="http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view&current=IMG_0673.jpg&sort=ascending" title="IMG_0673.jpg"><img src="http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/th_IMG_0673.jpg" alt="IMG_0673.jpg" /></a><br>F1 sidecar - IMG_0673.jpg</p></description>
<guid>http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg</guid>
<enclosure type="image/jpeg" url="http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg" />
<media:content medium="image" type="image/jpeg" url="http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg">
<media:title>F1 car</media:title>
<media:description />
<media:thumbnail url="http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/th_IMG_0673.jpg" />
</media:content>
<pubDate>Sun, 7 Aug 2011 20:11:31 MDT</pubDate>
</item>
나는 그 가치를 얻기 위해 요소에 가고 싶습니다. 여기
use strict;
use CGI;
use XML::RSS;
use LWP::Simple;
my $test = CGI->new;
my $url = "http://feed1100.photobucket.com/albums/g409/BlahBlah/websitePic/feed.rss";
my $rss = XML::RSS->new();
my $data = get($url);
$rss->parse($data);
$rss->add_module(prefix=>'media', uri=>'http://search.yahoo.com/mrss/');
print $test->header("text/html");
my $channel = $rss->{channel};
foreach my $item (@{ $rss->{items} })
{
my $link = $item->{link};
my $title = $item->{title};
my $thumb = '';
foreach my $b ({ $item->{'http://search.yahoo.com/mrss/'}->{'content'} })
{
print "here\n";
if($b->{'http://search.yahoo.com/mrss/'}->{'thumbnail'}->{'url'})
{
$thumb = $thumb . ' ' . $b->{'http://search.yahoo.com/mrss/'}->{'thumbnail'}->{'url'};
}
}
print $title, "\n", $link, "\nthumb=", $thumb, "\n\n\n";
}
print $test->end_html;
이 반복됩니다 모든 채널 항목의를 통해 작동하지 않습니다 내 코드는 ..., 그리고 요소를 찾을 수 있습니다,하지만 난 자식 요소를 얻을 수없는 것. 제 문법은 가깝다고 생각합니다. 아이디어?
이것은 내가 원하는 요소이며 요소의 'url'속성이 필요합니다.하지만 고마워, 나는 데이터 덤프를 시도 할 것이다. –
MonkeyWrench