symfony/dom-crawler
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
masterminds/html5 | 2.9.0 | - | MIT | prod | |
symfony/polyfill-ctype | v1.29.0 | - | MIT | prod | |
symfony/polyfill-mbstring | v1.29.0 | - | MIT | prod |
The Symfony/Dom-Crawler is a powerful utility that enables swift and comfortable navigation for HTML and XML documents. With this, developers can traverse node trees, inspect elements, extract data, and manipulate content efficiently, making it a vital tool for web data mining and scraping projects.
Using Symfony/Dom-Crawler is pretty straightforward. First of all, you will need to install composer package in your PHP project by running this command:
composer require symfony/dom-crawler
Once the package is installed, you can utilize it in your PHP code. A basic example might look like this:
<?php
use Symfony\Component\DomCrawler\Crawler;
$html = '<html>... your html ...</html>';
$crawler = new Crawler($html);
// Access elements using CSS Selectors
$titleElement = $crawler->filter('h1.title');
$title = $titleElement->text();
echo 'The title is: '. $title;
In this example, we initially create a Crawler
object with your HTML document as the input. Here we're using filter()
method to find the h1.title
HTML element in the document, then extracting the contained text.
For advanced usage and comprehensive understanding of Symfony/Dom-Crawler, refer to their official documentation. This resource provides an in-depth breakdown of what the component offers - from installation to the various methods available for DOM manipulation and navigation. It is a handy reference when integrating Symfony/Dom-Crawler into your web development projects.