How to select elements by class using CSS selectors?

by scrapecrow Apr 20, 2023

To select elements by class value the . symbol + value can be used. For example, .product would select any element that contains product in the class attribute:

<div> <div class="product">select</div> <div class="sold product">select</div> <div class="sold product new">select</div> <div class="product-2">ignore</div> </div>

Note that this selector matches any element that contains a class value in the class list (separated by spaces).
To match elements that contain the exact class value the predicate syntax can be used:

<div> <div class="product">ignore</div> <div class="sold product">select</div> <div class="sold product new">ignore</div> <div class="product-2">ignore</div> </div>

Related Articles

How to Parse XML

In this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate them for data extraction.

PYTHON
CSS-SELECTORS
XPATH
DATA-PARSING
How to Parse XML

Ultimate CSS Selector Cheatsheet for HTML Parsing

Ultimate companion for HTML parsing using CSS selectors. This cheatsheet contains all syntax explanations with interactive examples.

CSS-SELECTORS
DATA-PARSING
Ultimate CSS Selector Cheatsheet for HTML Parsing

Web Scraping With Ruby

Introduction to web scraping with Ruby. How to handle http connections, parse html files for data, best practices, tips and an example project.

RUBY
HTTP
DATA-PARSING
CSS-SELECTORS
XPATH
INTRO
Web Scraping With Ruby

Web Scraping With NodeJS and Javascript

In this article we'll take a look at scraping using Javascript through NodeJS. We'll cover common web scraping libraries, frequently encountered challenges and wrap everything up by scraping etsy.com

NODEJS
HTTP
DATA-PARSING
CSS-SELECTORS
INTRO
Web Scraping With NodeJS and Javascript

Parsing HTML with CSS Selectors

Introduction to using CSS selectors to parse web-scraped content. Best practices, available tools and common challenges by interactive examples.

DATA-PARSING
CSS-SELECTORS
Parsing HTML with CSS Selectors

How to Scrape YouTube in 2025

Learn how to scrape YouTube, channel, video, and comment data using Python directly in JSON.

SCRAPEGUIDE
PYTHON
HIDDEN-API
How to Scrape YouTube in 2025