--- title: "Write an XPath for web scraping - Mozenda" slug: "create-xpath" description: "XPath for web scraping lets you specify an HTML element or a set of HTML elements. This article provides the basic elements you need to get started, but keep in mind that there are many ways to write an XPath. Take the time to practice and find a method that works for you." tags: ["location", "change location", "alternate location", "new location", "agent", "troubleshooting", "writing", "customization", "language", "query", "nodes", "HTML"] updated: 2024-05-14T12:14:13Z published: 2024-05-14T12:14:13Z canonical: "help.mozenda.com/create-xpath" --- > ## Documentation Index > Fetch the complete documentation index at: https://help.mozenda.com/llms.txt > Use this file to discover all available pages before exploring further. # Create an XPath expression XPath lets you specify an HTML element or a set of HTML elements. This article provides the instructions you need to get started, but keep in mind that there are many ways to write an XPath expression. Take the time to practice and find a method that works for you. ### XPath Syntax has three elements - **Axis**: Specifies the tree relationship and the direction to navigate from node to node. - **Node test**: The name of the HTML element you want to select. - **Zero or more predicates**: Filters a node to refine results. These can be functions, numbers, or operators within square brackets. ### Identify an object in HTML HTML elements have a tag name, attibutes, values, and content. ``` Content on website ``` 1. **Right-click** an item on the web page. 2. Select **Inspect**. 3. Press **Ctrl+F** to search for the XPath match. ### Writing XPath Take your time to become familiar with the website and the HTML. Find similarities between the HTML and the text on the website. These landmarks will help you choose predicates, filters, that are readable and reliable. HTML elements have a tag name, attibutes, values, and content ``` Content on website ``` Each XPath expression will start with an axis, the direction of where to travel, the tag name of the element you want and a predicate or filter. The filter is structured similar to a math equation and the order of operations. The predicate would be applied between two square brackets each `contains` function being applied is placed between the parenthesis. Let's simplify the HTML element as if you were searching for a family tree for a specific person. To write your first XPath expression, specify the axis and name, then add a filter in brackets. ![image.png](https://cdn.document360.io/03076343-9561-4857-8a4e-9f3bfed20ced/Images/Documentation/image%2819%29.png) We want to search all HTML elements , so we'll set our axis to *descendant-or-self* using the short-hand "// ." The name of the element is "travis." To filter out any other potential matches, we'll add a filter using the attribute of hair that is equal to brown. ![Screen Shot 2020-03-24 at 9.45.28 PM.png](https://cdn.document360.io/03076343-9561-4857-8a4e-9f3bfed20ced/Images/Documentation/Screen%20Shot%202020-03-24%20at%209.45.28%20PM.png) **Practice:** Write an XPath expression to select the div below. ![Screen Shot 2020-03-24 at 9.51.49 PM.png](https://cdn.document360.io/03076343-9561-4857-8a4e-9f3bfed20ced/Images/Documentation/Screen%20Shot%202020-03-24%20at%209.51.49%20PM.png) **answer**: //div[@id="mozenda"]