title: Scraping specific text from a webpage using xpath
body: <p>I've searched and tried multiple ways to get this but I'm not sure why it won't find most of the information on the webpage.</p>
  
  <p>Page to scrape:
  <a href="https://m.safeguardproperties.com/" rel="nofollow noreferrer">https://m.safeguardproperties.com/</a></p>
  
  <p>Info needed:
  Version number for PhotoDirect for Apple (currently 4.4.0)</p>
  
  <p>Xpath to text needed (I think) : /html/body/div[1]/div[2]/div[1]/div[4]/div[3]/a</p>
  
  <p>Attempts:</p>
  
  <pre><code>&lt;?php
  
  $file = "https://m.safeguardproperties.com/";
  $doc = new DOMDocument();
  $doc-&gt;loadHTMLFile($file);
  
  $xpath = new DOMXpath($doc);
  
  $elements = $xpath-&gt;query("/html/body/div[1]/div[2]/div[1]/div[4]/div[3]/a");
  
  echo "&lt;PRE&gt;";
  
  if (!is_null($elements)) {
    foreach ($elements as $element) {
        var_dump ($element);
      echo "&lt;br/&gt;[". $element-&gt;nodeName. "]";
  
      $nodes = $element-&gt;childNodes;
      foreach ($nodes as $node) {
        echo $node-&gt;nodeValue. "\n";
      }
    }
  }
  
  echo "&lt;/PRE&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>Second Attempt:</p>
  
  <pre><code>&lt;?PHP
  $file = "https://m.safeguardproperties.com/";
  $doc = new DOMDocument();
  $doc-&gt;loadHTMLFile($file);
  
  echo '&lt;pre&gt;';
  
    // trying to find all links in document to see if I can see the correct one
    $links = [];
    $arr = $doc-&gt;getElementsByTagName("a");
  
    foreach($arr as $item) { 
      $href =  $item-&gt;getAttribute("href");
      $text = trim(preg_replace("/[\r\n]+/", " ", $item-&gt;nodeValue));
      $links[] = [
        'href' =&gt; $href,
        'text' =&gt; $text
      ];
    }
  
  var_dump($links);
  echo '&lt;/pre&gt;';
  ?&gt;
  </code></pre>