Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Css Selector Laravel Package

symfony/css-selector

Converts CSS selectors to XPath expressions, letting you query HTML and XML documents with familiar CSS syntax. A port of Python's cssselect library, part of the Symfony framework.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy on selector compilation. The alternative to adopting this is writing (and maintaining) a CSS-to-XPath translator ourselves. It is a 7,416-star, MIT-licensed, Symfony-maintained port of Python's cssselect, already present transitively in any Laravel app running Dusk or symfony/dom-crawler. The build option costs engineering weeks plus permanent maintenance; the buy option costs one composer require. That asymmetry should end the debate.
  • Whether to invest in content extraction / ingestion. The moment a roadmap item involves "pull structured data out of HTML" — competitor pricing, supplier catalogues, documentation ingestion for RAG, content migration — selector compilation becomes a real dependency of a real feature. This package supplies the querying primitives; it does not supply fetching, JS execution, or sanitisation, so it de-risks only one slice of that roadmap item and must not be presented as progress toward it.
  • Whether to offer a customer-facing "define what to extract" surface. The component makes it trivially cheap to let users type article.product h2.title instead of an XPath expression. That is a genuine product differentiator (lower activation energy, familiar syntax) and simultaneously the single biggest decision in this assessment: user-authored selectors convert a pure utility into an untrusted-input security boundary.
  • HTML regression testing for transactional email and marketing templates. Asserting "the unsubscribe link exists in the footer, the hero image has alt text, the CTA button markup didn't drift" is exactly the DomCrawler + css-selector use case. This is a quality-gate decision with a clear owner (QA / lifecycle marketing) and a small, bounded cost.
  • Test-authoring ergonomics for engineering. Dusk acceptance tests read better with ->assertSee-adjacent CSS selectors than hand-written XPath. This is a developer-productivity decision, made once, that compounds across every future test.
  • Pinning posture as a product-safety requirement. The changelog reads as a threat model: quadratic token probing in Reader::findPattern() (#65599), a nesting-depth cap on :is()/:where() (#65596), and an LRU cache added to CssSelectorConverter to stop memory exhaustion (#63400) — all denial-of-service-class, all only reachable with attacker-supplied selectors. A minimum-version pin plus a patch-SLA is a product decision, not a lockfile chore.
  • Syntax contract and support-load forecasting. :is()/:where() arrived in 7.1, :has() in 8.1. :hover, :focus, and ::before are unsupported and cannot be supported (no browser in the loop). Users will type them anyway. Publishing a supported-syntax contract with inline validation is a scope decision that prevents a predictable ticket queue.

When to Consider This Package

Adopt when:

  • You are already running Laravel Dusk, symfony/dom-crawler, BrowserKit, or Panther — in which case the package is likely already in composer.lock, and the real decision is whether to promote it to a direct dependency, pin it, and build product surface on it.
  • You hold HTML or XML in a DOMDocument and want CSS-syntax querying without hand-writing XPath.
  • Selectors will be authored by your own engineers (test suites, internal scrapers) — the low-risk, high-ergonomics case.
  • You accept that your production PHP floor governs capability: Symfony 8.x needs PHP ≥ 8.4, 7.x needs 8.2+, 6.4 needs 8.1+. A team standardised on PHP 8.2/8.3 resolves to 7.4.x, so :has() may be unavailable on day one. Design around this rather than argue with it.
  • You want a MIT-licensed dependency with a predictable, well-resourced maintenance story (parallel patches across 5.4/6.4/7.4/8.x, including LTS branches).

Look elsewhere — or scope more work — when:

  • Pages are client-rendered. No JavaScript is executed here. You need a headless browser (Panther, Puppeteer, Playwright) and its own operational cost.
  • Selectors come from customers. You can still proceed, but only with inline validation, a supported-syntax contract, minimum-version pinning, error rendering, and a named owner for patch SLAs. Budget that as feature work.
  • You need CSS semantics beyond querying — specificity scoring, cascade resolution, inlining styles into email HTML, or style sanitisation. This component converts selectors to XPath; it does nothing else.
  • You need rendering pseudo-classes (:hover, :focus, ::before, ::after) or XPath 2.0/3.0. Neither is in scope.
  • You are evaluating it by GitHub metadata alone. "Dependents: 0" is misleading — the real graph is DomCrawler, BrowserKit, Panther, Dusk, and effectively every PHP crawler and HTML-testing library. Likewise, "latest release" tells you nothing useful; the split-repository structure means issues and PRs live in symfony/symfony.

How to Pitch It (Stakeholders)

For executives: this is a zero-incremental-cost, MIT-licensed, Symfony-maintained component that is almost certainly already inside our application via Dusk or DomCrawler. It converts familiar CSS selectors into XPath so that our engineers — and, optionally, our customers — can target elements in HTML without learning XPath. It opens no sockets, holds no state, registers no service provider or migration, and can be removed without touching persistence or transport. The dependency itself should be sized at approximately zero engineering effort; the value we capture is entirely in the feature built on top of it — content extraction, scrape-target definition, template regression testing, or a customer-facing selector UI.

For engineering: treat it as a pure, stateless translation function, CssSelectorConverter::toXPath(), or reach it through DomCrawler's filter(). There is one seam — selector compilation — and libxml's DOMXPath does the matching. The two things that need your attention are (1) dependency pinning, because the last several patch releases fix DoS-class defects reachable only via user-authored selectors, and (2) the capability ceiling: current pseudo-class support depends on our PHP floor, and rendering pseudo-classes are out of scope by design. Enablement material is on us — the upstream docs are Symfony-component-shaped, with no Laravel, Blade, or Dusk examples.

The honest framing: we are not adopting a dependency, we are deciding to build a feature. The dependency is hours; the feature — validation, syntax contract, error UX, ownership of upgrades — is the roadmap slot. Do not let "we added css-selector" appear on a status slide as progress toward a scraping or content-ingestion initiative. It does not fetch pages, execute JavaScript, inline styles, or sanitise markup; each of those is a separate decision with a separate owner. The one question that must be answered before committing is: who authors selectors — our engineers, or our customers? If engineers, this is a developer-ergonomics choice. If customers, it is a security-posture choice, and the required validation and pinning work grows by an order of magnitude.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections