<?php
require '../oauth_secret.inc';
$url = 'http://query.yahooapis.com/v1/yql';
try {
    $o = new OAuth($consumerKey,$consumerSecret,
                   OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
    $q = <<<EOB
select * from html where xpath=
'//tr//a[@href="/wiki/Capital_(political)"]/../../../td[2]/a/text()'
and url in (select url from search.web where url like '%wikipedia%'
            and query='Denmark' limit 1)
EOB;
    $o->fetch("$url?q=".rawurlencode($q)."&format=json");
/* Uncomment for debugging
    $response_info = $o->getLastResponseInfo();
    echo "<pre>".print_r($response_info,true)."</pre>";
*/
    $result = json_decode($o->getLastResponse(),true);
    foreach($result['query']['diagnostics']['url'] as $u) {
       echo "{$u['content']}<br>\n";
    }
    echo "<b>Answer: </b>{$result['query']['results']}";
} catch(Exception $E) {
    echo "Error: [".$E->errorMessage."]<br>\n";
    echo "Response: [".$E->lastResponse."]<br>\n";
    exit;
}
?> 

http://boss.yahooapis.com/ysearch/web/v1/Denmark?format=xml&start=0&count=10
http://en.wikipedia.org/robots.txt
http://en.wikipedia.org/wiki/Denmark
Answer: Copenhagen