2017-05-14 76 views
0

如何凑使用gouttelaravel一个<a>链接data-属性?使用goutte scrape data-属性?

我想刮一个标签,像这样:

<a class="ProfileNav-stat ProfileNav-stat--link u-borderUserColor u-textCenter js-tooltip js-nav u-textUserColor" data-nav="following" href="/rogerhamilton/following" data-original-title="987,358 Following"> 

<a>链路内我想接着刮data-original-title标签。

我的代码是:

$client = new Client(); 

// Hackery to allow HTTPS 
$guzzleclient = new \GuzzleHttp\Client([ 
    'timeout' => 60, 
    'verify' => false, 
]); 

// Hackery to allow HTTPS 
$client->setClient($guzzleclient); 
$crawler = $client->request('GET', 'url'); 


$elements = $crawler->filter('.ProfileNav-stat.ProfileNav-stat--link')->each(function($node){ 
    $x = $node->filter('data-original-title'); 
    dd($x); 
}); 

,但它不返回正确的数据。

回答

1

为别人自带翻过这一问题。它的过滤简单到链接,然后执行类似$node->filter('.classname or #ID')->attr('data-original-title')的操作。