dongtangu8403 2013-02-08 10:33
浏览 41

从rss feed获取图片网址?

I need to get image url from this rss feed. I am using dom document for get get data

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[Accessories]]></title>
    <link>http://abcde.com/accessories</link>
    <description><![CDATA[Accessories]]></description>
    <pubDate>Fri, 08 Feb 2013 10:16:45 +0000</pubDate>
    <generator>Zend_Feed</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Jabra HALO 2 JBRA2113 Wireless Headset]]></title>
      <link>http://abcde.com/accessories/jabra-halo-2-jbra2113-wireless-headset</link>
      <description><![CDATA[<table><tr><td><a href="http://abcde.com/accessories/jabra-halo-2-jbra2113-wireless-headset"><img src="http://abcde.com/media/catalog/product/cache/1/thumbnail/75x75/9df78eab33525d08d6e5fb8d27136e95/h/a/halo2_frontview_1440x810.jpg" border="0" align="left" height="75" width="75"></a></td><td  style="text-decoration:none;">






    <div class="price-box">
                                                            <span class="regular-price" id="product-price-1041"><span class="price">Rs. 6,499.00</span></span>

        </div>

</td></tr></table>]]></description>
      <pubDate>Fri, 08 Feb 2013 10:16:45 +0000</pubDate>
    </item>

  </channel>
</rss>

Expected output:

http://abcde.com/media/catalog/product/cache/1/thumbnail/75x75/9df78eab33525d08d6e5fb8d27136e95/h/a/halo2_frontview_1440x810.jpg

Now i am getting details like this...

$doc = new DOMDocument();
$doc->load('http://feeds.gawker.com/lifehacker/full');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {

$a = $node->getElementsByTagName('title')->item(0)->nodeValue;
$a = $node->getElementsByTagName('image')->item(0)->nodeValue;

}
  • 写回答

1条回答 默认 最新

  • duandeng2011 2013-02-08 10:36
    关注

    Maybe you want to get only img src-s:

    "#<img[^>]+src=[\"|']([^\"]*)[\"|']#"
    

    so the example would be

    preg_replace_callback("#<img[^>]+src=[\"|']([^\"]*)[\"|']#",function($matches){print_r($matches[1]);return $matches[0];},' '.$STR.' ');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比