Reputation: 112
For this div:
<section class='menu'>
<div class="some beautiful classes" link="/some/path/in/web">
<div class="contImgHome">
<img src="/images/icon.jpg alt="">
</div>
<h5>
<a href="javascript:void(0);">Go to Section</a>
</h5>
</div>
<div class="some beautiful classes" link="/another/path/in/web">
<div class="contImgHome">
<img src="/images/icon.jpg alt="">
</div>
<h5>
<a href="javascript:void(0);">Go to another section</a>
</h5>
</div>
</section>
I make:
$response = $guzzleClient->request('GET', $url_base);
$crawler = new Crawler( (string) $response->getBody() );
$crawler->filter('section.menu > div')->each(function( Crawler $div, $i )
{
$xx = $div->extract( [ 'class', 'link'] );
print_r( $xx );
echo PHP_EOL;
die;
});
And return this:
Array
(
[0] => Array
(
[0] => some beautiful classes
[1] =>
)
)
I also tried with:
$div->attr('classes');
$div->attr('link');
But 'link' attribute is always empty. ¿Why I cant get "link" attribute?
I'm using Laravel 5.2 and installed Symfony Crawler vía composer.
Upvotes: 0
Views: 1307
Reputation: 112
It was my mistake!
Web set that "link" attribute with javascript using Document Ready, so attr is not existing when Crawler gets page DOM.
Upvotes: 1