@@ -370,16 +370,28 @@ This behavior is best illustrated with examples::
370
370
Links
371
371
~~~~~
372
372
373
- To find a link by name (or a clickable image by its ``alt `` attribute), use
374
- the ``selectLink() `` method on an existing crawler. This returns a ``Crawler ``
375
- instance with just the selected link(s). Calling ``link() `` gives you a special
376
- :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object::
373
+ To find a link by its ``id `` or its ``class `` attribute(s), use the ``filter() ``
374
+ method on an existing crawler. To find a link by name (or a clickable image by
375
+ its ``alt `` attribute), use the ``selectLink() `` method on an existing crawler.
376
+ This returns a ``Crawler `` instance with just the selected link(s). Calling
377
+ ``link() `` gives you a special :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object::
377
378
378
- $linksCrawler = $crawler->selectLink('Go elsewhere...');
379
- $link = $linksCrawler->link();
379
+ // select the link by its id
380
+ $linksByIdCrawler = $crawler->filter('#your-link');
381
+ $link = $linksByIdCrawler->link();
382
+
383
+ // select the link by its class
384
+ $linksByClassCrawler = $crawler->filter('.link');
385
+ $link = $linksByClassCrawler->link();
386
+
387
+ // select the link by its name
388
+ $linksByNameCrawler = $crawler->selectLink('Go elsewhere...');
389
+ $linkByName = $linksCrawler->link();
380
390
381
391
// or do this all at once
382
- $link = $crawler->selectLink('Go elsewhere...')->link();
392
+ $linkById = $crawler->filter('#your-link')->link();
393
+ $linkByClass = $crawler->filter('.link')->link();
394
+ $linkByName = $crawler->selectLink('Go elsewhere...')->link();
383
395
384
396
The :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object has several useful
385
397
methods to get more information about the selected link itself::
0 commit comments