对于这个 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>
我做:
$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;
});
并返回:
Array
(
[0] => Array
(
[0] => some beautiful classes
[1] =>
)
)
我也尝试过:
$div->attr('classes');
$div->attr('link');
但“链接”属性始终为空。¿ 为什么我无法获得“链接”属性?
我正在使用 Laravel 5.2 并通过作曲家安装了 Symfony Crawler。