yahooのニュースAPIはトピックスしか取れなくて使えない。
yahoo search boss の News Search は記事が取得できる。
やったー。
参考:[を] Yahoo! Search BOSS が出たので試してみました
<?php ini_set('include_path', "/home/aaa/public_html/PEAR:" . ini_get('include_path')); require_once "XML/Unserializer.php"; $query = rawurlencode($_POST['query']); if($query != "") { $appid = "アプリケーションID"; $start = "0"; $count = "50"; if ($_POST['kind'] == "news") { $age = "1"; $searchurl = "http://boss.yahooapis.com/ysearch/news/v1/{$query}?appid={$appid}&format=xml&age={$age}d&lang=jp®ion=jp&start={$start}&count={$count}"; } else { $searchurl = "http://boss.yahooapis.com/ysearch/web/v1/{$query}?appid={$appid}&format=xml&lang=jp®ion=jp&start={$start}&count={$count}"; } $data = file_get_contents($searchurl); if(!is_null($data)) { $options = array( XML_UNSERIALIZER_OPTION_RETURN_RESULT => true, XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE => true, ); $unserializer = new XML_Unserializer($options); $unserialized_data = $unserializer->unserialize($data); } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>yahoo search boss test</title> </head> <body> <form action="<?php $_SERVER['PHP_SELF']?>" method="POST"> <input type="text" name="query" value="<?=htmlspecialchars($_POST['query'])?>"> <input type="submit" value="Search"> <input type="radio" name="kind" id="kind_news" value="news"<?=$_POST['kind']==news?" checked":""?>> <label for="kind_news">news</label> <input type="radio" name="kind" id="kind_plane" value="plane"<?=$_POST['kind']==plane?" checked":""?>> <label for="kind_plane">plane</label> </form> <div> <?=isset($searchurl)?$searchurl:""?> </div> <div> <?php if (isset($unserialized_data)) { //print_r($unserialized_data); if ($_POST['kind'] == "news") { if (is_array($unserialized_data['resultset_news']['result'])) { foreach($unserialized_data['resultset_news']['result'] as $r) { print "<div>\n"; print "<h2><a href=\"{$r['clickurl']}\">{$r['title']}</a></h2>\n"; print "<p>{$r['abstract']}</p>\n"; print "<p>{$r['date']} {$r['time']}</p>\n"; print "<p><a href=\"{$r['sourceurl']}\">{$r['source']}</a></p>\n"; print "</div>\n"; } } } else { if (is_array($unserialized_data['resultset_web']['result'])) { foreach($unserialized_data['resultset_web']['result'] as $r) { print "<div>\n"; print "<h2><a href=\"{$r['clickurl']}\">{$r['title']}</a></h2>\n"; print "<p>{$r['abstract']}</p>\n"; print "</div>\n"; } } } } ?> </div> </body> </html>