How to find HTML elements by multiple tags with DOM Crawler?

You can find HTML elements by multiple tags with DOM Crawler by pairing the filter method with a CSS selector that includes multiple tag names separated by commas. Here's an example that loads ScrapingBee's homepage using Guzzle and then prints the text of all h1 and h2 tags using Dom Crawler:

use Symfony\Component\DomCrawler\Crawler;
use GuzzleHttp\Client;

// Create a client to make the HTTP request
$client = new \GuzzleHttp\Client();
$response = $client->get('');
$html = (string) $response->getBody();

// Load the HTML document
$crawler = new Crawler($html);

// Find all h1 and h2 headings on the page
$headings = $crawler->filter('h1, h2');

// Loop over the headings and print their text content
foreach ($headings as $element) {
    echo $element->textContent . PHP_EOL;

// Output:
// Tired of getting blocked while scraping the web?
// Render your web page as if it were a real browser.
// Render JavaScript to scrape any website.
// Rotate proxies to bypass rate limiting.
// Simple, transparent pricing.
// Developers are asking...
// Who are we?
// Contact us
// Ready to get started?

Related DOM Crawler web scraping questions: