Skip to content

Instantly share code, notes, and snippets.

@xabbuh
Created April 22, 2016 10:34
Show Gist options
  • Save xabbuh/ad04b9dad5424b8c6af4260d1da15af0 to your computer and use it in GitHub Desktop.
Save xabbuh/ad04b9dad5424b8c6af4260d1da15af0 to your computer and use it in GitHub Desktop.
<?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