     [Answers](https://scrapfly.io/blog)   /  [xpath](https://scrapfly.io/blog/tag/xpath)   /  [How to select elements by attribute value in XPath?](https://scrapfly.io/blog/answers/how-to-select-elements-by-attribute-value)   # How to select elements by attribute value in XPath?

 by [Bernardas Alisauskas](https://scrapfly.io/blog/author/bernardas) May 02, 2023 1 min read [\#xpath](https://scrapfly.io/blog/tag/xpath) 

 [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value "Share on LinkedIn")    

 

 

XPath allows interacting with any element's attribute such as `class`, `id`, `href` and any other through the `@` syntax. Attribute values then can be used in predicates using `=` or `contains()`. See these interactive examples:

Select attribute value, like the urls of `<a>` links:

&lt;html&gt; &lt;a href="/categories/1"&gt;category&lt;/a&gt; &lt;a href="/product/1"&gt;product 1&lt;/a&gt; &lt;a href="/product/2"&gt;product 2&lt;/a&gt; &lt;a href="/product/3"&gt;product 3&lt;/a&gt; &lt;/html&gt; Or filter element based by attribute using `contains()` function:

&lt;html&gt; &lt;a href="/categories/1"&gt;category&lt;/a&gt; &lt;a href="/product/1"&gt;product 1&lt;/a&gt; &lt;a href="/product/2"&gt;product 2&lt;/a&gt; &lt;a href="/product/3"&gt;product 3&lt;/a&gt; &lt;/html&gt; 

 

   Table of Contents















 

   Join the Newsletter  Get monthly web scraping insights 

 

  



Scale Your Web Scraping

Anti-bot bypass, browser rendering, and rotating proxies, all in one API. Start with 1,000 free credits.

  No credit card required  1,000 free API credits  Anti-bot bypass included 

 [Start Free](https://scrapfly.io/register) [View Docs](https://scrapfly.io/docs/onboarding) 

 Not ready? Get our newsletter instead. 

 

## Explore this Article with AI

 [ ChatGPT ](https://chat.openai.com/?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value) [ Gemini ](https://www.google.com/search?udm=50&aep=11&q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value) [ Grok ](https://x.com/i/grok?text=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value) [ Perplexity ](https://www.perplexity.ai/search/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value) [ Claude ](https://claude.ai/new?q=Summarize%20this%20page%3A%20https%3A%2F%2Fscrapfly.io%2Fblog%2Fanswers%2Fhow-to-select-elements-by-attribute-value) 



 ## Related Articles

 [  

 data-parsing xpath 

### Ultimate XPath Cheatsheet for HTML Parsing in Web Scraping

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

 

 ](https://scrapfly.io/blog/posts/xpath-cheatsheet) [  

 python data-parsing 

### Parsing HTML with Xpath

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

 

 ](https://scrapfly.io/blog/posts/parsing-html-with-xpath) [  

 python ai 

### Find Web Elements with ChatGPT and XPath or CSS selectors

ChatGPT is becoming a popular assistant in web scraper development. In this article, we'll take a look at how to use it ...

 

 ](https://scrapfly.io/blog/posts/finding-web-selectors-with-chatgpt) 

  ## Related Questions

- [ Q How to select elements by class in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-class-in-xpath)
- [ Q How to find elements without a specific attribute in BeautifulSoup? ](https://scrapfly.io/blog/answers/how-to-find-elements-without-attribute-in-beautifulsoup)
- [ Q How to select elements by ID in XPath? ](https://scrapfly.io/blog/answers/how-to-select-elements-by-id-in-xpath)
- [ Q How to find HTML elements by text value with BeautifulSoup ](https://scrapfly.io/blog/answers/how-to-find-html-elements-by-text-with-beautifulsoup)
 
  



   



 Scale your web scraping effortlessly, **1,000 free credits** [Start Free](https://scrapfly.io/register)