Created
April 22, 2016 10:34
-
-
Save xabbuh/ad04b9dad5424b8c6af4260d1da15af0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\DomCrawler\Crawler; | |
$html = <<<EOT | |
<html> | |
<head></head> | |
<body> | |
<div class="content"> | |
<ul> | |
<li></li> | |
<li></li> | |
<li></li> | |
<li></li> | |
<li></li> | |
<li id="sold-by-merchant"></li> | |
<li></li> | |
<li></li> | |
<li></li> | |
<script type="text/javascript"></script> | |
<li style="overflow:hidden;"></li> | |
<script type="text/javascript"></script> | |
<li></li> | |
<li></li> | |
<li style="overflow:hidden;"></li> | |
<script type="text/javascript"></script> | |
</ul> | |
</div> | |
</body> | |
</html> | |
EOT; | |
$nodesFound = 0; | |
$crawler = new Crawler($html); | |
$crawler->filter('.content > ul > li')->each(function () use (&$nodesFound) { | |
$nodesFound++; | |
}); | |
echo $nodesFound; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment