Working with XPaths
An XPath is an expression that points at elements on a web page. For example, //h1 selects every <h1> heading. Site Search 360 uses XPaths to decide which title, images and text it takes from your pages, and where your data points sit.
Where to find it: Data Structuring → Content Extraction, and the XPath fields of Data Points and Result Groups
Common patterns
| XPath | Selects |
|---|---|
//h1 | Every <h1> element. |
//div[@id="main"] | The <div id="main"> element, for example the main content without footer and sidebars. |
//p[contains(@class,"notes")] | <p> elements whose class includes notes, such as <p class="intro notes">. |
//img[contains(@class,"main-image")]/@src | The src attribute of images whose class includes main-image: the image URL. |
//meta[@property="og:image"]/@content | The value of a meta tag. End an XPath with /@name to read any attribute. |
If you know CSS selectors better, this CSS-to-XPath conversion table translates them.
Find an XPath with XPath Helper
-
Install the XPath Helper Chrome extension.
-
Open a page of your website and click the XPath Helper icon in the toolbar.
-
Hold Shift and hover over the element you want. XPath Helper shows its XPath in the QUERY box and the matched text in RESULTS.
-
Shorten the XPath so it matches the same element on every page, not just this one:
- Remove steps from the front and start the XPath with
//. An element with anidis a good starting point. - Replace long class lists with
contains(@class,'…').
For example, this XPath from XPath Helper:
/html/body[@id='body']/main/section[@class='u-pb-xxl u-pb-xl--sm']/article[@class='flex container'][1]/div[@class='main-feature__content col-6 col-12-sm']works on every page shortened to:
//*[@id='body']//div[contains(@class,'main-feature__content')] - Remove steps from the front and start the XPath with
-
Paste it into the Control Panel field and test it there: Test extraction on Content Extraction, or Extraction Preview for a data point. Index Single URL under Index shows everything extracted from one page.
XPaths in Content Extraction
Each field takes one or more XPaths. After a change, re-index your site. Content Extraction explains every setting.
Title XPaths
Title XPath points at the title of each page. Without one, the crawler picks the title automatically. Common values are //h1, or //title for the HTML <title> tag.
The Regular Expression below it keeps only part of the title. For example, if every title ends in your brand:
<title>Working with XPaths – Site Search 360</title>
set Title XPath to //title and Regular Expression to [^–]+. The title becomes "Working with XPaths", without "– Site Search 360".
Image XPaths
Image XPath points at the main image of each page, shown as the result's thumbnail. Leave it empty if the automatic image detection picks the right image. To choose it:
//img[@id='main']/@src
For lazy-loaded images, read the attribute that holds the real URL, often data-src:
//div[@class='product-detail-images']//img/@data-src
Include and Exclude Content XPaths
Include Content XPath limits the indexed text to the elements it matches, for example //main. Exclude Content XPath leaves elements out, for example //footer or //nav. Leave both empty to index the whole page.
Search snippet XPath
To show a fixed text under each result, such as the meta description, instead of the text around the search term, set the Search Snippet Source to Use content behind search snippet XPath under Search Snippet. The default XPath reads the meta description:
//meta[@name="description"]/@content