Grabbing links using xpath in php

rogergi

New Member
i am trying to grab links from the Google search page. i am using the be below xpath to \[code\]//div[@id='ires']/ol[@id='rso']/li/h3/a/@href\[/code\]grab the links. xPather evaluates it and gives the result. But when i use it with my php it doesn't show any result. Can someone please tell me what I am doing wrong? There is nothing wrong with the cURL.below is my code\[code\]$dom = new DOMDocument();@$dom->loadHTML($result);$xpath=new DOMXPath($dom);$elements = $xpath->evaluate("//div[@id='ires']/ol[@id='rso']/li/h3/a");foreach ($elements as $element){ $link = $element->getElementsByTagName("href")->item(0)->nodeValue; echo $link."<br>";}\[/code\]Sample Html provided by Robert Pitt\[code\]<li class="g w0"> <h3 class="r"> <a href="" class="l"><em>LINK</em></a> </h3> <button class="ws" title=""></button> <div class="s"> META </div></li>\[/code\]
 
Back
Top