{"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":"python","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,"search_vec":"'1.11.0':48 'activ':53 'chang':68 'common':38 'content':34 'css':20,76 'current':45 'cycl':55 'data':11,79 'depend':39,66 'design':8 'develop':54 'document':16 'effici':27 'extract':10,80 'flexibl':25 'frequent':57 'html':13,71 'jmespath':78 'librari':7 'maintain':51 'make':35 'navig':30 'often':59 'pars':72,74 'parsel':1,2 'power':5 'provid':23 'python':6,62 'queri':32 'requir':67 'scrape':42,70 'selector':21,77 'support':64 'tie':60 'tool':43 'updat':58 'use':17 'version':46,63 'way':28 'web':33,41,69 'xml':15,73 'xpath':18,75","created_at":"2026-04-09T18:46:53.932080+00:00","updated_at":"2026-04-16T17:53:34.601519+00:00","problems":[{"fix":"Install the parsel library using pip: `pip install parsel`","cause":"The 'parsel' library is not installed in the Python environment being used, or there is a mismatch between the Python environment where it was installed and the one executing the script.","error":"ModuleNotFoundError: No module named 'parsel'"},{"fix":"Carefully review and correct the XPath syntax. Use browser developer tools or online XPath validators to test and verify the XPath expression against your document.","cause":"The XPath expression provided to the parsel Selector contains a syntax error or is malformed.","error":"ValueError: XPath error: exception"},{"fix":"Inspect the HTML structure using browser developer tools to ensure the selector is correct and matches the desired elements. If the content is dynamic, consider using a tool like Selenium to render the JavaScript before parsing.","cause":"The CSS or XPath selector provided does not match any elements in the HTML/XML document, or the content you are trying to extract is dynamically loaded via JavaScript and is not present in the initial HTML source.","error":"No data extracted (or empty list returned by .css()/.xpath())"},{"fix":"Update both `parsel` and the dependent library (e.g., Scrapy) to their latest compatible versions, or pin `parsel` to a version known to be compatible with your current dependent library version. For instance, `pip install parsel==<compatible_version> Scrapy==<compatible_version>`.","cause":"This error typically indicates an incompatibility between the `parsel` library and a dependent library (such as Scrapy) that expects a specific internal attribute or method which has been changed or removed in a newer `parsel` version.","error":"AttributeError: 'Selector' object has no attribute '_default_type'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.11.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://parsel.readthedocs.io","github":"https://github.com/scrapy/parsel","docs":"https://parsel.readthedocs.io/en/latest/","changelog":"https://parsel.readthedocs.io/en/latest/history.html","pypi":"https://pypi.org/project/parsel/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","serialization","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}