dongqianzong4275 2016-01-11 19:20
浏览 33

使用PHP从Google自定义搜索rss中获取价值

I have a Google Custom search RSS that gives me this xml (simplified):

<?xml version="1.0" encoding="UTF-8"?>

 <title>Google Custom Search - the rocky horror picture show 1975</title>

 <entry gd:kind="customsearch#result">
   <id>http://www.imdb.com/title/tt0073629/</id>
   <cse:PageMap>
     <cse:DataObject type="metatags">
       <cse:Attribute name="og:image" value="http://URLtoAnImage.com/image.jpg"/>
<!-- and so on... -->

I managed to get the value of "id" (http://www.imdb.com/title/tt0073629/) into an array ($item) with this php:

$rss = new DOMDocument();
$rss->load($myRSS); // the RSS URL

$feed = array();

foreach ($rss->getElementsByTagName('entry') as $node) {
    $item = array ( 
       'link' => $node->getElementsByTagName('id')->item(0)->nodeValue,
        );
    array_push($feed, $item);
    break; //break because I only want the first search result (entry)
}

Can someone please help me get the "og:image" value into the same array with the same php code?

Or do I need a different php code?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效