How to get the name of an HTML element in XPath?

by scrapecrow Apr 19, 2023

To get the name of the selected element in XPath the name() function can be used. This function returns the name of the closest element in the current context.

The name() function is useful in HTML parsing in broad selection cases like selecting multiple names. See this interactive example:

<!-- select all links by selecting the @href attributes --> <article> <p>paragraph 1</p> <a>link 1</a> <p>paragraph 2</p> <script>some script data</script> <p>paragraph 3</p> </article>

Above, we're selecting only paragraph and link elements by using wildcard match (the * symbol) and a name() matching predicate.

Related Articles

How to Parse XML

In this article, we'll explain about XML parsing. We'll start by defining XML files, their format and how to navigate them for data extraction.

PYTHON
CSS-SELECTORS
XPATH
DATA-PARSING
How to Parse XML

Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Ultimate companion for HTML parsing using XPath selectors. This cheatsheet contains all syntax explanations with interactive examples.

XPATH
DATA-PARSING
Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

Web Scraping With Ruby

Introduction to web scraping with Ruby. How to handle http connections, parse html files for data, best practices, tips and an example project.

RUBY
HTTP
DATA-PARSING
CSS-SELECTORS
XPATH
INTRO
Web Scraping With Ruby

Parsing HTML with Xpath

Introduction to xpath in the context of web-scraping. How to extract data from HTML documents using xpath, best practices and available tools.

DATA-PARSING
PARSEL
XPATH
PYTHON
Parsing HTML with Xpath

Web Scraping With PHP 101

Introduction to web scraping with PHP. How to handle http connections, parse html files for data, best practices, tips and an example project.

PHP
HTTP
DATA-PARSING
XPATH
INTRO
Web Scraping With PHP 101

Web Scraping With Scrapy: The Complete Guide in 2025

Tutorial on web scraping with scrapy and Python through a real world example project. Best practices, extension highlights and common challenges.

PYTHON
SCRAPY
FRAMEWORK
XPATH
INTRO
Web Scraping With Scrapy: The Complete Guide in 2025