Skip to content

Commit bd6fa15

Browse files
committed
feature #4971 [DomCrawler] Document images crawler (valeriangalliat)
This PR was merged into the master branch. Discussion ---------- [DomCrawler] Document images crawler | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#13649, symfony/symfony#13650) | Applies to | 3.0.0 | Fixed tickets | symfony/symfony#12429 Commits ------- 355a83f [DomCrawler] Document images crawler
2 parents 097e379 + 355a83f commit bd6fa15

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
@@ -49,9 +49,11 @@ which are basically nodes that you can traverse easily::
4949
var_dump($domElement->nodeName);
5050
}
5151

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

5658
.. note::
5759

@@ -293,7 +295,7 @@ Links
293295
~~~~~
294296

295297
To find a link by name (or a clickable image by its ``alt`` attribute), use
296-
the ``selectLink`` method on an existing crawler. This returns a Crawler
298+
the ``selectLink`` method on an existing crawler. This returns a ``Crawler``
297299
instance with just the selected link(s). Calling ``link()`` gives you a special
298300
:class:`Symfony\\Component\\DomCrawler\\Link` object::
299301

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

322+
Images
323+
~~~~~~
324+
325+
To find an image by its ``alt`` attribute, use the ``selectImage`` method on an
326+
existing crawler. This returns a ``Crawler`` instance with just the selected
327+
image(s). Calling ``image()`` gives you a special
328+
:class:`Symfony\\Component\\DomCrawler\\Image` object::
329+
330+
$imagesCrawler = $crawler->selectImage('Kitten');
331+
$image = $imagesCrawler->image();
332+
333+
// or do this all at once
334+
$image = $crawler->selectImage('Kitten')->image();
335+
336+
The :class:`Symfony\\Component\\DomCrawler\\Image` object has the same
337+
``getUri()`` method as :class:`Symfony\\Component\\DomCrawler\\Link`.
338+
320339
Forms
321340
~~~~~
322341

0 commit comments

Comments
 (0)