@@ -424,16 +424,26 @@ This behavior is best illustrated with examples::
424
424
Links
425
425
~~~~~
426
426
427
- To find a link by name (or a clickable image by its ``alt `` attribute), use
428
- the ``selectLink() `` method on an existing crawler. This returns a ``Crawler ``
429
- instance with just the selected link(s). Calling ``link() `` gives you a special
430
- :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object::
431
-
432
- $linksCrawler = $crawler->selectLink('Go elsewhere...');
433
- $link = $linksCrawler->link();
434
-
435
- // or do this all at once
436
- $link = $crawler->selectLink('Go elsewhere...')->link();
427
+ Use the ``filter() `` method to find links by their ``id `` or ``class ``
428
+ attributes and use the ``selectLink() `` method to find links by their content
429
+ (it also finds clickable images with that content in its ``alt `` attribute).
430
+
431
+ Both methods return a ``Crawler `` instance with just the selected link. Use the
432
+ ``link() `` method to get the :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object
433
+ that represents the link::
434
+
435
+ // first, select the link by id, class or content...
436
+ $linkCrawler = $crawler->filter('#sign-up');
437
+ $linkCrawler = $crawler->filter('.user-profile');
438
+ $linkCrawler = $crawler->selectLink('Log in');
439
+
440
+ // ...then, get the Link object:
441
+ $link = $linkCrawler->link();
442
+
443
+ // or do all this at once:
444
+ $link = $crawler->filter('#sign-up')->link();
445
+ $link = $crawler->filter('.user-profile')->link();
446
+ $link = $crawler->selectLink('Log in')->link();
437
447
438
448
The :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object has several useful
439
449
methods to get more information about the selected link itself::
0 commit comments