PHPackages                             jerodev/diggy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jerodev/diggy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jerodev/diggy
=============

A fluent PHP web scraper

2.1(1y ago)33.5kMITPHPPHP ^8.1

Since Feb 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jerodev/diggy)[ Packagist](https://packagist.org/packages/jerodev/diggy)[ RSS](/packages/jerodev-diggy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Diggy web scraper
=================

[](#diggy-web-scraper)

[![PHP tests](https://github.com/jerodev/diggy/workflows/PHP%20tests/badge.svg)](https://github.com/jerodev/diggy/workflows/PHP%20tests/badge.svg) [![Latest Stable Version](https://camo.githubusercontent.com/174f41b17b8886a1ae7250c7bc9bacc3de22100ab4e559e773124eeefbafb16c/68747470733a2f2f706f7365722e707567782e6f72672f6a65726f6465762f64696767792f76)](//packagist.org/packages/jerodev/diggy)

Diggy is a simple wrapper around the [PHP DOM extension](https://www.php.net/manual/en/intro.dom.php) that allow finding elements using simple query selectors and fail proof chaining.

Requirements
------------

[](#requirements)

- PHP 8.1

Getting started
---------------

[](#getting-started)

Diggy includes a simple webclient that uses Guzzle under the hood to download a page and return a `NodeCollection`object. However, you can use any webclient you prefer and pass a `DOMNode` or `DOMNodeList` object to the `NodeCollection` constructor.

```
$client = new \Jerodev\Diggy\WebClient();
$page = $client->get('https://www.deviaene.eu/');

$socials = $page->first('#social')->querySelector('a span')->texts();
var_dump($socials);

//    [
//        'GitHub',
//        'Twitter',
//        'Email',
//        'LinkedIn',
//    ]
```

Available functions
-------------------

[](#available-functions)

These are the available functions on a `NodeCollection` object. All functions that do not return a native value can be chained without having to worry if there are nodes in the collection or not.

### `attribute(string $name)`

[](#attributestring-name)

Returns the value of the attribute of the first element in the collection if available.

```
$nodes->attribute('href');
```

### `count()`

[](#count)

Returns the number of elements in the current node collection.

```
$nodes->count();
```

### `each(string $selector, closure $closure, ?int $max = null)`

[](#eachstring-selector-closure-closure-int-max--null)

Loops over all dom elements in the current collection and executes a closure for each element. The return value of this function is an array of values returned from the closure.

```
$nodes->each('a', static function (NodeFilter $node) {
    return $a->attribute('href');
});
```

### `exists(?string $selector = null)`

[](#existsstring-selector--null)

Indicates if an element exists in the collection. If a selector is given, the current nodes will first be filtered.

```
$nodes->exists('a.active');
```

### `filter(closure $closure)`

[](#filterclosure-closure)

Filters the current node collection based on a given closure.

```
$nodes->filter(static function (NodeFilter $node) {
    return $node->text() === 'foo';
});
```

### `first(?string $selector = null)`

[](#firststring-selector--null)

Returns the first element of the node collection. If a selector is given, the current nodes will first be filtered.

```
$nodes->first('a.active');
```

### `is(string $nodeName)`

[](#isstring-nodename)

Indicates if the first element in the current collection has a specified tag name.

```
$nodes->is('div');
```

### `last(?string $selector = null)`

[](#laststring-selector--null)

Returns the last element of the node collection. If a selector is given, the current nodes will first be filtered.

```
$nodes->last('a.active');
```

### `nodeName()`

[](#nodename)

Returns the tag name of the first element in the current node collection

```
$nodes->nodeName();
```

### `nth(int $index, ?string $selector = null)`

[](#nthint-index-string-selector--null)

Returns the nth element of the node collection, starting at `0`. If a selector is given, the current nodes will first be filtered.

```
$nodes->nth(1, 'a.active');
```

### `querySelector(string $selector)`

[](#queryselectorstring-selector)

Finds all elements in the current node collection matching this css query selector.

```
$nodes->querySelector('a.active');
```

### `text(?string $selector = null)`

[](#textstring-selector--null)

Returns the inner text of the first element in the node collection. If a selector is given, the current nodes will first be filtered.

```
$nodes->text('p.description');
```

### `texts()`

[](#texts)

Returns an array containing the inner text of every root element in the collection.

```
$nodes->texts('nav > a');
```

### `whereHas(closure $closure)`

[](#wherehasclosure-closure)

Filter nodes that contain child nodes that fulfill the filter described by the closure

```
$nodes->whereHas(static function (NodeFilter $node) {
    return $node->first('a[href]');
});
```

### `whereHasAttribute(string $key, ?string $value = null)`

[](#wherehasattributestring-key-string-value--null)

Filters the current node collection by the existence of a specific attribute. If a value is given the collection is also filtered by the value of this attribute.

```
$nodes->whereHasAttribute('href');
```

### `whereHasText(?string $value = null, bool $trim = true, bool $exact = false)`

[](#wherehastextstring-value--null-bool-trim--true-bool-exact--false)

Filters the current node collection by the existence of inner text. Setting a value will also filter the nodes by the actual inner text based on `$trim` and `$exact`.

optionfunction`$trim`Indicates the inner text value should be trimmed before matches with `$value`.`$exact`Indicates the inner text value should match `$value` exactly.```
$nodes->whereHasText('foo');
```

### `xPath(string $selector)`

[](#xpathstring-selector)

Finds all elements in the current node collection matching this xpath query selector.

```
$nodes->xPath('//nav/a[@href]');
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~302 days

Total

5

Last Release

710d ago

Major Versions

1.1.0 → 2.02022-10-31

PHP version history (2 changes)1.0PHP ^7.4|^8.0

2.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/de99d8fde875ca88a6b812d7b4ab34f0e4a198cd1a7443ca09df33f943c02379?d=identicon)[jerodev](/maintainers/jerodev)

---

Top Contributors

[![jerodev](https://avatars.githubusercontent.com/u/3493941?v=4)](https://github.com/jerodev "jerodev (28 commits)")

---

Tags

phpwebscraper

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jerodev-diggy/health.svg)

```
[![Health](https://phpackages.com/badges/jerodev-diggy/health.svg)](https://phpackages.com/packages/jerodev-diggy)
```

###  Alternatives

[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
