# Parsel

[![Tests](https://github.com/scrapy/parsel/actions/workflows/tests-ubuntu.yml/badge.svg)](https://github.com/scrapy/parsel/actions/workflows/tests-ubuntu.yml)[![Supported Python versions](https://img.shields.io/pypi/pyversions/parsel.svg)](https://pypi.python.org/pypi/parsel)[![PyPI Version](https://img.shields.io/pypi/v/parsel.svg)](https://pypi.python.org/pypi/parsel)[![Coverage report](https://img.shields.io/codecov/c/github/scrapy/parsel/master.svg)](https://codecov.io/github/scrapy/parsel?branch=master)

Parsel is a BSD-licensed [Python](https://www.python.org/) library to extract data from [HTML](https://en.wikipedia.org/wiki/HTML), [JSON](https://en.wikipedia.org/wiki/JSON), and
[XML](https://en.wikipedia.org/wiki/XML) documents.

It supports:

- [CSS](https://en.wikipedia.org/wiki/Cascading_Style_Sheets) and [XPath](https://en.wikipedia.org/wiki/XPath) expressions for HTML and XML documents
- [JMESPath](https://jmespath.org/) and [JSONPath](https://datatracker.ietf.org/doc/html/rfc9535) expressions for JSON documents
- [Regular expressions](https://docs.python.org/library/re.html)

Find the Parsel online documentation at [https://parsel.readthedocs.org](https://parsel.readthedocs.org).

Example ([open online demo](https://colab.research.google.com/drive/149VFa6Px3wg7S3SEnUqk--TyBrKplxCN#forceEdit=true&sandboxMode=true)):

```pycon
>>> from parsel import Selector
>>> text = """
... <html>
...     <body>
...         <h1>Hello, Parsel!</h1>
...         <ul>
...             <li><a href="http://example.com">Link 1</a></li>
...             <li><a href="http://scrapy.org">Link 2</a></li>
...         </ul>
...         <script type="application/json">{"a": ["b", "c"]}</script>
...     </body>
... </html>"""
>>> selector = Selector(text=text)
>>> selector.css("h1::text").get()
'Hello, Parsel!'
>>> selector.xpath("//h1/text()").re(r"\w+")
['Hello', 'Parsel']
>>> for li in selector.css("ul > li"):
...     print(li.xpath(".//@href").get())
...
http://example.com
http://scrapy.org
>>> selector.css("script::text").jmespath("a").get()
'b'
>>> selector.css("script::text").jmespath("a").getall()
['b', 'c']
```

## Parsel Documentation Contents

Contents:

* [Installation](installation.md)
* [Usage](usage.md)
* [XPath Tutorial](xpath-tutorial.md)
* [API reference](parsel.md)
* [History](history.md)
