2017-05-14 73 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')的操作。