{"id":2179,"library":"parsel","title":"Parsel","description":"Parsel is a powerful Python library designed to extract data from HTML and XML documents using XPath and CSS selectors. It provides a flexible and efficient way to navigate and query web content, making it a common dependency for web scraping tools. The current version is 1.11.0, and it maintains an active development cycle with frequent updates, often tied to Python version support and dependency requirement changes.","status":"active","version":"1.11.0","language":"en","source_language":"en","source_url":"https://github.com/scrapy/parsel","tags":["web scraping","html parsing","xml parsing","xpath","css selectors","jmespath","data extraction"],"install":[{"cmd":"pip install parsel","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core parsing engine for HTML/XML. Minimum version >= 5.1.0 since Parsel 1.11.0.","package":"lxml","optional":false},{"reason":"Used for version comparisons within the library. Minimum version >= 23.0 since Parsel 1.11.0.","package":"packaging","optional":false},{"reason":"Enables JMESPath queries for JSON documents. Minimum version >= 1.0.0 since Parsel 1.11.0. Introduced in Parsel 1.8.0.","package":"jmespath","optional":false},{"reason":"Enables CSS selector functionality. Minimum version >= 1.2.0 since Parsel 1.9.0 (though required since 1.8.0).","package":"cssselect","optional":false}],"imports":[{"symbol":"Selector","correct":"from parsel import Selector"},{"note":"Typically obtained as a result of a Selector method, but can be imported directly for type hinting or specific use cases.","symbol":"SelectorList","correct":"from parsel import SelectorList"}],"quickstart":{"code":"from parsel import Selector\n\nhtml_doc = '''\n<html>\n<head><title>My Awesome Page</title></head>\n<body>\n    <div id=\"main\">\n        <h1>Hello Parsel!</h1>\n        <p class=\"intro\">This is an <a href=\"/example\">introductory</a> paragraph.</p>\n        <ul>\n            <li>Item 1</li>\n            <li>Item 2</li>\n        </ul>\n    </div>\n</body>\n</html>\n'''\n\n# Create a Selector from HTML text\nselector = Selector(text=html_doc)\n\n# Extract title using CSS selector\ntitle = selector.css('title::text').get()\nprint(f\"Title: {title}\")\n\n# Extract H1 text using XPath\nh1_text = selector.xpath('//h1/text()').get()\nprint(f\"H1 Text: {h1_text}\")\n\n# Extract all list items using CSS selector\nlist_items = selector.css('ul li::text').getall()\nprint(f\"List Items: {list_items}\")\n\n# Extract attribute using CSS selector\nlink_href = selector.css('.intro a::attr(href)').get()\nprint(f\"Link href: {link_href}\")\n\n# Example with JSON and JMESPath (Parsel >= 1.8.0)\njson_doc = '{\"data\": {\"products\": [{\"id\": 1, \"name\": \"Laptop\"}, {\"id\": 2, \"name\": \"Mouse\"}]}}'\njson_selector = Selector(text=json_doc, type='json')\nproduct_names = json_selector.jmespath('data.products[*].name').getall()\nprint(f\"Product names (JMESPath): {product_names}\")","lang":"python","description":"This quickstart demonstrates how to initialize a `Selector` from HTML or JSON text, and then use both CSS selectors and XPath expressions to extract data. It also includes an example of JMESPath usage for JSON documents, introduced in Parsel 1.8.0."},"warnings":[{"fix":"Ensure your project runs on Python 3.10 or newer (Parsel 1.11.0 requires >=3.10). Refer to the release notes for specific version requirements.","message":"Support for older Python versions (3.9, PyPy 3.10) has been removed in 1.11.0. Earlier versions (3.8, 3.7, 3.6, 3.5, 2.7) were removed in previous releases.","severity":"breaking","affected_versions":"1.7.0, 1.9.0, 1.10.0, 1.11.0"},{"fix":"Migrate your code to use the `Selector.drop()` and `SelectorList.drop()` methods, which provide similar functionality, instead of the removed `remove()` methods.","message":"The `Selector.remove()` and `SelectorList.remove()` methods, deprecated in 1.7.0, have been entirely removed.","severity":"breaking","affected_versions":"1.7.0 - 1.11.0"},{"fix":"If you relied on the implicit `\"utf8\"` encoding name, explicitly specify `encoding='utf8'` in `Selector` constructor or update your code to use the standard `\"utf-8\"`.","message":"The default encoding name for documents loaded via `body` or when parsing changed from `\"utf8\"` to `\"utf-8\"` due to compatibility issues in some environments.","severity":"breaking","affected_versions":"1.10.0+"},{"fix":"Update your project's dependencies to satisfy Parsel's new minimum requirements (e.g., `lxml >= 5.1.0`, `packaging >= 23.0`, `jmespath >= 1.0.0`, `cssselect >= 1.2.0`).","message":"Minimum supported versions for core dependencies like `lxml`, `packaging`, `jmespath`, and `cssselect` have been bumped.","severity":"breaking","affected_versions":"1.9.0, 1.11.0+"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}