pyquery runs jQuery-like selectors over HTML or XML using lxml, loading documents from strings, files, or URLs.
Overview
pyquery brings a jQuery-flavored API to Python for searching and changing HTML or XML trees. It relies on lxml for parsing and manipulation, and is meant for server-side or script use rather than driving browser JavaScript.
The PyQuery wrapper can be built from markup strings, existing lxml elements, local files, or remote URLs, optionally with a custom opener for fetching pages. Once loaded, CSS selectors pick nodes, and methods mirror familiar jQuery calls to read or rewrite HTML and text content.
Support includes nonstandard pseudo-classes such as :first, :last, :even, :odd, :eq, and form-related selectors like :checked. Documentation covers attributes, traversal, CSS tweaks, scraping tips, and testing guidance, with further selector semantics aligned to jQuery references.
Teams adopt pyquery when they want concise DOM queries in Python pipelines—especially for scraping, templating tweaks, or test fixtures—without adopting a full browser automation stack.
Key features
- jQuery-like selector and manipulation API
- lxml-backed HTML and XML parsing
- Load from string, file, or URL
- Pseudo-class selectors beyond CSS
- HTML and text content get/set
- Custom URL openers
- Scraping-oriented documentation
- PyQuery chainable interface
Use cases
- HTML scraping and extraction
- Tweaking parsed markup in scripts
- Parsing XML configuration or feeds
- Test fixtures over saved HTML
- Familiar jQuery patterns in Python