使用perl解析Photobucket RSS提要?

使用perl解析Photobucket RSS提要?,perl,rss,Perl,Rss,试图从Photobucket读取和解析RSS提要,我很难找到元素的子元素。以下是RSS XML示例: <?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>

试图从Photobucket读取和解析RSS提要,我很难找到元素的子元素。以下是RSS XML示例:

<?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&apos;s Photobucket websitePic album media</title>
        <description>A feed of BlahBlah&apos;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&amp;current=IMG_0673.jpg&amp;sort=ascending</link>
            <dc:creator>BlahBlah</dc:creator>
            <description>&lt;p&gt;&lt;a href=&quot;http://s1100.photobucket.com/albums/g409/BlahBlah/&quot;&gt;BlahBlah&lt;/a&gt; posted a photo&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view&amp;current=IMG_0673.jpg&amp;sort=ascending&quot; title=&quot;IMG_0673.jpg&quot;&gt;&lt;img src=&quot;http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/th_IMG_0673.jpg&quot; alt=&quot;IMG_0673.jpg&quot; /&gt;&lt;/a&gt;&lt;br&gt;F1 sidecar - IMG_0673.jpg&lt;/p&gt;</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>

它将遍历所有通道项,并找到元素,但我似乎无法获得子元素。我觉得我的语法很接近。想法?

这行看起来像是打字错误:

foreach my $b ( { $item->{'http://search.yahoo.com/mrss/'}->{'content'} })

我想你在第一个“{”前面漏掉了一个“@”。

这行看起来像是打字错误:

foreach my $b ( { $item->{'http://search.yahoo.com/mrss/'}->{'content'} })

我认为您在第一个“{”前面缺少了一个“@”。

items
示例中的内容被解析为以下结构:

items => [
  {
    dc => {
      creator => "BlahBlah"
    },
    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>",
    enclosure => {
      type => "image/jpeg",
      url => "http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg"
    },
    guid => "http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg",
    "http://purl.org/dc/elements/1.1/" => {
      creator => "BlahBlah"
    },
    "http://search.yahoo.com/mrss/" => {
      content => "\n                ...",
      title => "F1 car"
    },
    isPermaLink => "",
    item => "\n            \n\n ...",
    link => "http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view&current=IMG_0673.jpg&sort=ascending",
    pubDate => "Sun, 7 Aug 2011 20:11:31 MDT",
    title => "F1 sidecar"
  }
],
items=>[
{
dc=>{
creator=>“BlahBlah”
},
description=>“发布了一张照片


F1侧车-IMG_0673.jpg

”, 附件=>{ 类型=>“图像/jpeg”, url=>”http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg" }, guid=>”http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg", "http://purl.org/dc/elements/1.1/" => { creator=>“BlahBlah” }, "http://search.yahoo.com/mrss/" => { 内容=>“\n…”, 标题=>“F1赛车” }, isPermaLink=>“”, item=>“\n\n\n…”, 链接=>”http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view¤t=IMG_0673.jpg&sort=ascending", pubDate=>“太阳报,2011年8月7日20:11:31 MDT”, 标题=>“F1侧车” } ],

例如,我在
下没有看到任何
的“缩略图”
键http://search.yahoo.com/mrss/“
。转储数据以查看它们的确切外观是个好主意。请参阅类似的模块。

项目
示例中的内容被解析为以下结构:

items => [
  {
    dc => {
      creator => "BlahBlah"
    },
    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>",
    enclosure => {
      type => "image/jpeg",
      url => "http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg"
    },
    guid => "http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg",
    "http://purl.org/dc/elements/1.1/" => {
      creator => "BlahBlah"
    },
    "http://search.yahoo.com/mrss/" => {
      content => "\n                ...",
      title => "F1 car"
    },
    isPermaLink => "",
    item => "\n            \n\n ...",
    link => "http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view&current=IMG_0673.jpg&sort=ascending",
    pubDate => "Sun, 7 Aug 2011 20:11:31 MDT",
    title => "F1 sidecar"
  }
],
items=>[
{
dc=>{
creator=>“BlahBlah”
},
description=>“发布了一张照片


F1侧车-IMG_0673.jpg

”, 附件=>{ 类型=>“图像/jpeg”, url=>”http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg" }, guid=>”http://i1100.photobucket.com/albums/g409/BlahBlah/websitePic/IMG_0673.jpg", "http://purl.org/dc/elements/1.1/" => { creator=>“BlahBlah” }, "http://search.yahoo.com/mrss/" => { 内容=>“\n…”, 标题=>“F1赛车” }, isPermaLink=>“”, item=>“\n\n\n…”, 链接=>”http://s1100.photobucket.com/albums/g409/BlahBlah/websitePic/?action=view¤t=IMG_0673.jpg&sort=ascending", pubDate=>“太阳报,2011年8月7日20:11:31 MDT”, 标题=>“F1侧车” } ],

例如,我在
下没有看到任何
的“缩略图”
键http://search.yahoo.com/mrss/
。转储数据以查看它们的确切外观是一个好主意。请参阅类似模块的内容。

如果这样做,则会出现以下错误:不能使用字符串(“…”)作为数组引用,而使用“严格引用”在使用中我不确定。我想我从来没有“愉快地”处理过XML::RSS使用的名称空间语法。不过,这确实意味着,
$item->{http://search.yahoo.com/mrss/“}->{'content'}
不是您可以迭代的内容。您需要找到不同的方法。我建议插入“use Data::Dumper;print Dumper”($item);“就在foreach上方,告诉您其中实际包含的内容。也可能不是每篇文章都有一个media:content标记,在这种情况下,您需要首先检测该标记。如果检测到,则会出现以下错误:不能使用字符串(“…”)作为数组引用,而使用“strict refs”在使用中我不确定。我想我从来没有“愉快地”处理过XML::RSS使用的名称空间语法。不过,这确实意味着,
$item->{http://search.yahoo.com/mrss/“}->{'content'}
不是您可以迭代的内容。您需要找到不同的方法。我建议插入“use Data::Dumper;print Dumper”($项目);”就在你的foreach上面,告诉你里面到底有什么。也可能不是每个帖子都有media:content标签,在这种情况下,你需要首先检测它。这是我想要的元素,我需要元素的“url”属性:但是谢谢,我会尝试数据转储。这是我想要的元素,并且我需要元素的“url”属性:但是谢谢,我将尝试数据转储。