How to find HTML elements by multiple tags with Cheerio?

You can find HTML elements by multiple tags in Cheerio by separating the tag selectors with a ,.

Here's some sample code that demonstrates how to find all div and span elements using Cheerio:

const cheerio = require('cheerio');
const html = `
  <div>This is a div element</div>
  <span>This is a span element</span>
  <div>This is another div element</div>
`;

// Load the HTML content into a Cheerio object
const $ = cheerio.load(html);

// Find all div and span elements
const divsAndSpans = $('div, span');

// Iterate over each div and span element and print its text content
divsAndSpans.each((i, element) => {
    console.log($(element).text());
});

// Output:
// This is a div element
// This is a span element
// This is another div element

Related Cheerio web scraping questions: