How to scrape html contents of one div by id using php -


the page on of domains i'd scrape 1 div contains:

<div id="thisone">     <p>stuff</p> </div>  <div id="notthisone">     <p>more stuff</p> </div> 

using php...

<?php     $page = file_get_contents('http://thisite.org/source.html');     $doc = new domdocument();     $doc->loadhtml($page);     foreach ($doc->getelementsbytagname('div') $node) {         echo $doc->savehtml($node), php_eol;     } ?> 

...gives me divs on http://thisite.org/source.html, html. however, want pull through div id of "thisone" using:

foreach ($doc->getelementbyid('thisone') $node) { 

doesn't bring anything.

$doc->getelementbyid('thisone');// returns single element id 1 

try $node=$doc->getelementbyid('thisone'); , print $node

on side note, can use phpquery jquery syntext: pq("#thisone")


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -