title: Multiple html, head, body found with PHP xPath
body: <p>I'm using CURL, DOMDocument, loadHTML, DOMXPath in PHP to get the contents of URLs. In order to verify the validity of the data, I also run checks on the amount of html, head and body tags that were retrieved.</p>
  
  <p>My setup is working fine for the large majority of URLs I enter. However, for some URLs, an unexpected amount of those tags in reported. The xPaths: </p>
  
  <pre><code>$html = $this-&gt;runXpath('/html');
  $head = $this-&gt;runXpath('/html/head');
  $body = $this-&gt;runXpath('/html/body');
  </code></pre>
  
  <p>And the check:</p>
  
  <pre><code>if($html-&gt;length &gt; 1) {
   echo 'Too many html tags';
  }
  </code></pre>
  
  <ul>
  <li><a href="https://www.chownow.com/" rel="nofollow noreferrer">https://www.chownow.com/</a>: 2x HTML (yes, I see the iframe, but that is generated through Javascript, which CURL shouldn't render? Also, the xpath states that the html should be a child of #document - which, according to $tag->parentNode->nodeName both HTML elements are? The second HTML tag also doesn't show up in neither 'View source' nor the responsebody from the CURL request).</li>
  <li><a href="http://neilpatel.com/" rel="nofollow noreferrer">http://neilpatel.com/</a>: 2x HTML? (Once again a video, but seemingly not even a relevant iframe tag in the DOM source).</li>
  <li><a href="https://www.groovehq.com/" rel="nofollow noreferrer">https://www.groovehq.com/</a>: 2x BODY? (An iframe again, but no double html error, but a double body error instead?).</li>
  </ul>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Why does xpath seem to think there are multiple instances of those tags, while I can't find them as such in the CURL response body using ctrl-f when I output it, nor in 'View source'? </li>
  <li>How can I "see what xpath sees" in order to debug similar cases?</li>
  <li>It would almost seem that DOMDocument or xpath parses javascript, does it? If not, how do I explain the examples above?</li>
  </ol>
  
  <p>Any additional questions I will gladly answer. Thanks in advance!</p>