title: How to scrape html contents of one div by id using php
body: <p>The page on another of my domains which I'd like to scrape one div from contains:</p>
  
  <pre><code>&lt;div id="thisone"&gt;
      &lt;p&gt;Stuff&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div id="notthisone"&gt;
      &lt;p&gt;More stuff&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Using this php...</p>
  
  <pre><code>&lt;?php
      $page = file_get_contents('http://thisite.org/source.html');
      $doc = new DOMDocument();
      $doc-&gt;loadHTML($page);
      foreach ($doc-&gt;getElementsByTagName('div') as $node) {
          echo $doc-&gt;saveHtml($node), PHP_EOL;
      }
  ?&gt;
  </code></pre>
  
  <p>...gives me all divs on <a href="http://thisite.org/source.html" rel="nofollow">http://thisite.org/source.html</a>, with html. However, I only want to pull through the div with an id of "thisone" but using:</p>
  
  <pre><code>foreach ($doc-&gt;getElementById('thisone') as $node) {
  </code></pre>
  
  <p>doesn't bring up anything.</p>