hieK Posted September 5, 2014 Share Posted September 5, 2014 (edited) so i am trying to make my api for a website, and started coding a script for it. so far it looks like this <?php $ch = curl_init("http://www.gustos.ro/retete-culinare/saratele-din-faina-de-naut.html"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $rt = curl_exec($ch); $dom = new DOMDocument(); @$dom->loadHTML($rt); $xpath = new DOMXpath($dom); // title ("//h1[@class=textLarge7 extratextLarge7]/text()") $titleQuery = $xpath->query("//h1[@class=textLarge7 extratextLarge7]/text()"); echo $titleQuery; the problem is that when i try to echo it it wont give me the title ( only an error on line 17, that is the last line ) if it helps you when i try to execute print_r it gives me DOMNodeList Object ( ) Sorry for my bad english, its not my native language index.php Edited September 5, 2014 by hieK Quote Link to comment https://forums.phpfreaks.com/topic/290874-need-help-with-domxpath/ Share on other sites More sharing options...
hieK Posted September 5, 2014 Author Share Posted September 5, 2014 I`ve figured it out, it was because of the list, so i had to use node->nodeValue and worked Quote Link to comment https://forums.phpfreaks.com/topic/290874-need-help-with-domxpath/#findComment-1490058 Share on other sites More sharing options...
hieK Posted September 5, 2014 Author Share Posted September 5, 2014 So now i have another problem, <ul class="listType1 marginTop1"> <li itemprop="ingredients">13/4 pahar faina de naut</li> <li itemprop="ingredients">3/4 lingurita de sare</li> <li itemprop="ingredients">3/4 lingurita cardamon macinat marunt</li> <li itemprop="ingredients">1/2 lingurita piper negru macinat</li> <li itemprop="ingredients">11/2 pahare de apa</li> <li itemprop="ingredients">4 linguri ulei de masline</li> </ul> i cant figure out how to write the xpath query $ingredientsQuery = $xpath->query("//ul[@class=listType1 marginTop1]/text()"); but how do i integrate the li ? Quote Link to comment https://forums.phpfreaks.com/topic/290874-need-help-with-domxpath/#findComment-1490063 Share on other sites More sharing options...
nik_jain Posted September 5, 2014 Share Posted September 5, 2014 Dude xpath and DOM are a pain! Try the library Querypath (its a wrapper around DOMDocument). It takes the pain out of these things. Quote Link to comment https://forums.phpfreaks.com/topic/290874-need-help-with-domxpath/#findComment-1490066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.