This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DomCrawler
Fabien Potencier fea6b79acd moved component and bridge unit tests to the src/ directory
This is the first step to make each Symfony Component and Bridge self-contained.
2012-03-29 08:37:22 +02:00
..
Field [DoctrineBridge] fixed some CS 2011-12-13 10:22:12 +01:00
Tests moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00
composer.json Removed version field 2012-02-27 09:59:20 +01:00
Crawler.php [DomCrawler] removed the hard dependency on CssSelector 2012-03-28 18:08:10 +02:00
Form.php fixed CS, phpdoc, removed unused use statements 2012-01-28 18:02:36 +01:00
LICENSE Updated LICENSE files copyright 2012-02-22 10:10:37 +01:00
Link.php optimized string starts with checks 2012-01-11 11:33:56 -08:00
phpunit.xml.dist moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00
README.md moved component and bridge unit tests to the src/ directory 2012-03-29 08:37:22 +02:00

DomCrawler Component

DomCrawler eases DOM navigation for HTML and XML documents.

If you are familiar with jQuery, DomCrawler is a PHP equivalent:

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler();
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');

print $crawler->filterXPath('descendant-or-self::body/p')->text();

If you are also using the CssSelector component, you can use CSS Selectors instead of XPath expressions:

use Symfony\Component\DomCrawler\Crawler;

$crawler = new Crawler();
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');

print $crawler->filter('body > p')->text();

Resources

You can run the unit tests with the following command:

phpunit -c src/Symfony/Component/DomCrawler/

If you also want to run the unit tests that depend on other Symfony Components, declare the following environment variables before running PHPUnit:

export SYMFONY_CSS_SELECTOR=../path/to/CssSelector