2012-08-14 33 views
1

我正在使用Symfony2 DOMCrawler。我在頁面上有一個鏈接。我想通過鏈接並在那裏抓取一些內容。我該怎麼做?讓代碼是這樣Symfony2 DomCrawler鏈接

<a href="www.example.com">Go there</a> 

我知道$crawler->selectLink('Go there')->link();

回答

3

您正在尋找click()方法。

$link = $crawler->selectLink('Go there')->link(); 
$crawler = $client->click($link); 

你應該閱讀this documentation chapter多加小心

5

也許你正在尋找的東西,如:

$link = $crawler->filter('a[id="fabulous_id"]')->attr('href'); 
$crawler = $client->request('GET',$link); 

DomCrawler Doc的信息

+0

我覺得這是最好的解決方案的鏈接是不包含文本的按鈕,例如圖標按鈕。 – 2015-05-10 15:17:49

相關問題