Jump to content

Not sure whats wrong, xpath issues.


underv3

Recommended Posts

I am working on a program that can get bio's for music artists and i came across this

http://www.davidcraddock.net/2008/06/18/scraping-artists-bios-off-of-wikipedia/

It seems like a good start but when i attempted to run it I got some errors leading me to believe that the yahoo API implementation was outdated. Working from this i then added the "echo grabwiki(Rihanna);" as a test just to see if it would work. It looks as though everything works until it gets to "$b = $s->xpath("//p:abstract

[xml:lang='en']");". I have no idea what to do with this line of code. I've been playing around with the code and searching google but I can't seem to make it work.

The errors:
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Undefined namespace prefix in /home/jamesad/public_html/searchbio.php on line 16

Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in /home/jamesad/public_html/searchbio.php on line 16

<?php
function grabwiki($band){
    $band = urlencode($band);
    $yahoourl = 'http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=%22$band%22%20music&site=wikipedia.org';
    $x = file_get_contents($yahoourl);
    $s = new SimpleXMLElement($x);
    $ar = split('/',$s->Result->Url);
    if($ar[2] == 'en.wikipedia.org'){
      $wikikey = $ar[4]; // more than likely to be the wikipedia page
    }else{
      return ""; // nothing on wikipediea
    }
    $url = "http://dbpedia.org/data/$wikikey";
    $x = file_get_contents($url);
    $s = new SimpleXMLElement($x);
    $b = $s->xpath("//p:abstract[xml:lang='en']");
     return $b[0];
}
// if ($band == false) {
//    die("No Information Available");
//}
echo grabwiki(Rihanna);
?>

 

If someone has any ideas I would be open to any suggestions.

Thanks!  :)

Link to comment
https://forums.phpfreaks.com/topic/119868-not-sure-whats-wrong-xpath-issues/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.