title: Extract html with xpath and php
body: <p>I can't seem to find how to get values of a html page with xpath. I'm trying to retrieve the image source, price and name of each product on a page...I get as far as retrieving the number of products but somehow can't get any values after that...I'm definitely not a pro so that might explain;)</p>
  
  <p>I tried a few things. I can see the xpath in Chrome and tried to use those but it's always empty. at this point I'm lost on what to try.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div class="prod-main"&gt;
      &lt;div class="prod-thumb text-center" data-id="1948348"&gt;
          &lt;div class="prod-thumb-16-9"&gt;
          &lt;a href="#"&gt;&lt;img class="lazy" alt="" src="image.jpg"&gt;&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="prod-info"&gt;
          &lt;span class="prod-price"&gt;$8.00&lt;/span&gt;
          &lt;span class="prod-title"&gt;&lt;a href="#"&gt;Product Name&lt;/a&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;    
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>function url_get_contents ($Url) {
      if (!function_exists('curl_init')){ 
          die('CURL is not installed!');
      }
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $Url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $output = curl_exec($ch);
      curl_close($ch);
      return $output;
  }
  
      $newDom = new domDocument;
      $html=url_get_contents('test.html');
      $newDom-&gt;loadHTML($html);
      $newDom-&gt;preserveWhiteSpace = false;
      $finder = new DomXPath($newDom);
  
   $products = $finder-&gt;query('//div[@class="prod-main"]');
  
      foreach($products as $product) {
          $img = $finder-&gt;query('/div[2]/div/a/img/@src', $clip)[0]-&gt;value;
      }
  
  </code></pre>
  
  <p><code>phparray(24) { [0]=&gt; NULL [1]=&gt; NULL [2]=&gt; NULL [3]=&gt; NULL [4]=&gt; NULL [5]=&gt; NULL [6]=&gt; NULL [7]=&gt; NULL [8]=&gt; NULL [9]=&gt; NULL [10]=&gt; NULL [11]=&gt; NULL [12]=&gt; NULL [13]=&gt; NULL [14]=&gt; NULL [15]=&gt; NULL [16]=&gt; NULL [17]=&gt; NULL [18]=&gt; NULL [19]=&gt; NULL [20]=&gt; NULL [21]=&gt; NULL [22]=&gt; NULL [23]=&gt; NULL }</code></p>