Qined Community 🧑‍💻

Mohamed
Mohamed

Posted on

XPath Tutorial for SEO

What is XPath?

XPath (XML Path Language) is a language that allows the construction of expressions that traverse and search within an XML document. They are like regular expressions but they are used to select parts of the code based on their labels and attributes. XPath allows you to search and select taking into account the hierarchical structure of the XML.

XPATH Examples

These are some of the examples of XML Path Language.

XPath------------------------- Query

//a/@href----------------------- Links from a site
//to/text()--------------------- Anchor of the links
//title --------------------------------Title
//h1 --------------------------- H1
//h2 --------------------------- H2
//h3 --------------------------- H3
//link/@href-------------------- canonical link
//meta/@content------------------ Meta description
//meta/@content----------------- meta robots
//img/@src----------------------- Image URLs
//img/@alt---------------------- alt of images
//a/@href----------------------- Google xpath query
//div/a/@href------------------- Links from all Google posts
//link/@hreflang----------------- Hreflang
//link/@href-------------------- AMP Link

How to get XPath in Google Chrome

We can extract the XPATH of a web part by right-clicking on it and selecting "INSPECT".

The code of the web will open with the line of code of the selected element. We right-click on that line again and go to Copy > Copy Xpath.

And we will have our XPath copied to the clipboard ready to use in any tool.

Image description
Custom SEO extractions with Xpath and Screaming FROG
We can use the XPATH to do a massive extraction of all the URLs of a site with XPATH and include them in the crawl performed by Screaming FROG SEO.

Image description
We can add various fields including the XPATH that we want and select:

  • Extract Text: Extract the content between tags.
  • Extract Inner Html: Extract all HTML, tags and text.
  • Extract HTML Element: What is inside the HTML tag, either text or more HTML code

Image description

Uses SEO XPath

  • It can be used to extract breadcrumbs and thus know which category the URL we are in belongs to.
  • Analyze competition, for example product prices or stock.
  • Track opportunities, we can scrape fields likely to have SEO information (H1, title, metadescription...) and even make a content gap.

The XPATH has become relevant in SEO because it is used to extract and analyze information from web pages in an agile way.

And you? Do you use XPATH? What uses do you give it for SEO? We are waiting for you in the comments.

Discussion (0)