How to join values in XPath?

To join text in XPath the concat() function can be used. This is useful when parsing HTML for data values that are distributed through multiple elements or attributes.

See this interactive example:

<!-- select all product details as one string --> <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.

Provided by Scrapfly

This knowledgebase is provided by Scrapfly — a web scraping API that allows you to scrape any website without getting blocked and implements a dozens of other web scraping conveniences. Check us out 👇