@@ -399,16 +399,26 @@ This behavior is best illustrated with examples::
399
399
Links
400
400
~~~~~
401
401
402
- To find a link by name (or a clickable image by its ``alt `` attribute), use
403
- the ``selectLink() `` method on an existing crawler. This returns a ``Crawler ``
404
- instance with just the selected link(s). Calling ``link() `` gives you a special
405
- :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object::
406
-
407
- $linksCrawler = $crawler->selectLink('Go elsewhere...');
408
- $link = $linksCrawler->link();
409
-
410
- // or do this all at once
411
- $link = $crawler->selectLink('Go elsewhere...')->link();
402
+ Use the ``filter() `` method to find links by their ``id `` or ``class ``
403
+ attributes and use the ``selectLink() `` method to find links by their content
404
+ (it also finds clickable images with that content in its ``alt `` attribute).
405
+
406
+ Both methods return a ``Crawler `` instance with just the selected link. Use the
407
+ ``link() `` method to get the :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object
408
+ that represents the link::
409
+
410
+ // first, select the link by id, class or content...
411
+ $linkCrawler = $crawler->filter('#sign-up');
412
+ $linkCrawler = $crawler->filter('.user-profile');
413
+ $linkCrawler = $crawler->selectLink('Log in');
414
+
415
+ // ...then, get the Link object:
416
+ $link = $linkCrawler->link();
417
+
418
+ // or do all this at once:
419
+ $link = $crawler->filter('#sign-up')->link();
420
+ $link = $crawler->filter('.user-profile')->link();
421
+ $link = $crawler->selectLink('Log in')->link();
412
422
413
423
The :class: `Symfony\\ Component\\ DomCrawler\\ Link ` object has several useful
414
424
methods to get more information about the selected link itself::
0 commit comments