Query HTML elements by CSS class or tag when web scraping in PHP using a tool that only accepts XPath.
Add CSS selector support to a PHP HTML parser or test helper that uses XPath internally.
Avoid writing verbose XPath expressions by converting your existing CSS knowledge into XPath automatically.
This is a small PHP library that converts CSS selectors into XPath expressions. CSS selectors are the patterns that web developers use to target specific elements on a page, such as "all paragraphs inside a sidebar" or "the first item in a list." XPath is a different query language used to navigate and search through HTML or XML documents. Some PHP tools only understand XPath, so this library acts as a translator: you write the shorter, more familiar CSS syntax and get back the equivalent XPath query. The practical benefit is that CSS selectors are generally easier to read and write than XPath. A CSS selector like "div.article h2" is more compact than writing out the full XPath equivalent, which can become verbose. If you are doing web scraping, testing, or document parsing in PHP and your chosen tool accepts XPath, this library means you do not have to learn XPath syntax from scratch. You write CSS the way a front-end developer would, and the library handles the conversion behind the scenes. The library is part of the Symfony component ecosystem, a collection of standalone PHP packages maintained by the Symfony project. Each component is designed to be used independently from the rest of the framework, so you can pull in just this one piece without adopting the full Symfony stack. It was originally ported from a Python library called cssselect and is distributed under the BSD license. The README is short and does not include installation steps, usage examples, or configuration options. Full documentation is available on the official Symfony documentation site.
← symfony on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.