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.
| symfony/css-selector | symfony/var-dumper | sebastianbergmann/php-text-template | |
|---|---|---|---|
| Stars | 7,441 | 7,440 | 7,437 |
| Language | PHP | PHP | PHP |
| Setup difficulty | easy | easy | easy |
| Complexity | 2/5 | 1/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
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.
A small PHP library that converts CSS selectors into XPath queries, so you can use the familiar CSS syntax you already know when scraping or parsing HTML with PHP tools that require XPath.
Mainly PHP. The stack also includes PHP, Symfony.
Use freely for any purpose, including commercial projects, as long as you keep the BSD copyright notice.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.