Skip to content

Commit 355a83f

Browse files
[DomCrawler] Document images crawler
1 parent 81e8c13 commit 355a83f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

components/dom_crawler.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ traverse easily::
4848
print $domElement->nodeName;
4949
}
5050

51-
Specialized :class:`Symfony\\Component\\DomCrawler\\Link` and
51+
Specialized :class:`Symfony\\Component\\DomCrawler\\Link`,
52+
:class:`Symfony\\Component\\DomCrawler\\Image` and
5253
:class:`Symfony\\Component\\DomCrawler\\Form` classes are useful for
53-
interacting with html links and forms as you traverse through the HTML tree.
54+
interacting with html links, images and forms as you traverse through the HTML
55+
tree.
5456

5557
.. note::
5658

@@ -303,7 +305,7 @@ Links
303305
~~~~~
304306

305307
To find a link by name (or a clickable image by its ``alt`` attribute), use
306-
the ``selectLink`` method on an existing crawler. This returns a Crawler
308+
the ``selectLink`` method on an existing crawler. This returns a ``Crawler``
307309
instance with just the selected link(s). Calling ``link()`` gives you a special
308310
:class:`Symfony\\Component\\DomCrawler\\Link` object::
309311

@@ -327,6 +329,23 @@ methods to get more information about the selected link itself::
327329
page suffixed with ``#foo``. The return from ``getUri()`` is always a full
328330
URI that you can act on.
329331

332+
Images
333+
~~~~~~
334+
335+
To find an image by its ``alt`` attribute, use the ``selectImage`` method on an
336+
existing crawler. This returns a ``Crawler`` instance with just the selected
337+
image(s). Calling ``image()`` gives you a special
338+
:class:`Symfony\\Component\\DomCrawler\\Image` object::
339+
340+
$imagesCrawler = $crawler->selectImage('Kitten');
341+
$image = $imagesCrawler->image();
342+
343+
// or do this all at once
344+
$image = $crawler->selectImage('Kitten')->image();
345+
346+
The :class:`Symfony\\Component\\DomCrawler\\Image` object has the same
347+
``getUri()`` method as :class:`Symfony\\Component\\DomCrawler\\Link`.
348+
330349
Forms
331350
~~~~~
332351

0 commit comments

Comments
 (0)