🚀 We are hiring! See open positions

How to select elements by attribute value in XPath?

by Bernardas Alisauskas May 02, 2023 1 min read

XPath allows interacting with any element's attribute such as class, id, href and any other through the @ syntax. Attribute values then can be used in predicates using = or contains(). See these interactive examples:

Select attribute value, like the urls of <a> links:

<html> <a href="/categories/1">category</a> <a href="/product/1">product 1</a> <a href="/product/2">product 2</a> <a href="/product/3">product 3</a> </html>

Or filter element based by attribute using contains() function:

<html> <a href="/categories/1">category</a> <a href="/product/1">product 1</a> <a href="/product/2">product 2</a> <a href="/product/3">product 3</a> </html>
Scale Your Web Scraping
Anti-bot bypass, browser rendering, and rotating proxies — all in one API. Start with 1,000 free credits.
No credit card required 1,000 free API credits Anti-bot bypass included
Not ready? Get our newsletter instead.