🚀 We are hiring! See open positions

How to join values using XPath concat?

by Bernardas Alisauskas Aug 27, 2024 1 min read

The concat() function is an XPath expression is a string join function for multiple string values. It's useful when parsing an HTML document for a specific string through distributed multiple elements or attributes:

For example, let's see the below interactive XPath expression evaluation:

<html> <div> <h2>Coffee</h2> <span data-currency="USD">4.69</span> </div> </html>

Above, we contact the name and price elements into a single string. However, we can join any number of elements. Here's an example through two or more arguments:

<html> <div> <h2>Coffee</h2> <span data-currency="USD">4.69</span> </div></html>

Note that concat() only works with strings so it'll automatically try convert elements to their text() values. For further details on XPath selectors, including common tips and tricks, refer to our dedicated guide.

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.