Best practices

  • Use `[@class="classname"]` to select elements with an exact class match, ensuring precision in targeting specific elements.

  • Employ `contains(@class, "classname")` to find elements where the class attribute includes a particular class, useful for broader matches.

  • Utilize `contains(concat(" ", normalize-space(@class), " "), " classname ")` for accurate selection when targeting elements with multiple classes, ensuring the class is not part of another class name.

  • When selecting elements with a combination of specific classes, list all required classes in the attribute selector `[@class="class1 class2"]` to match the exact group of classes.

1
2
3
4
5
6
7
8
9
10
11
12
13

Common issues

  • Exact Class Matching: Avoid partial matches; always use exact class selectors for precise targeting.

  • Dynamic Classes: Use contains for elements with dynamically added or changing class parts.

  • Multiple Classes: Ensure isolation with concat(" ", normalize-space(@class), " ") to avoid false positives.

  • Order-Independent Classes: Combine multiple contains for class combinations without relying on order.

1
2
3
4
5
6
7
8
9
10
11
12
13

Try Oyxlabs' Proxies & Scraper API

Residential Proxies

Self-Service

Human-like scraping without IP blocking

From

8

Datacenter Proxies

Self-Service

Fast and reliable proxies for cost-efficient scraping

From

1.2

Web scraper API

Self-Service

Public data delivery from a majority of websites

From

49

Useful resources

Using Google Sheets for Basic Web Scraping visuals
Guide to Using Google Sheets for Basic Web Scraping
vytenis kaubre avatar

Vytenis Kaubrė

2025-07-18

Web Scraping With C#
Monika Maslauskaite avatar

Monika Maslauskaite

2023-12-06

XPath vs CSS Selectors
Monika Maslauskaite avatar

Monika Maslauskaite

2021-07-13

Get the latest news from data gathering world

I'm interested