Documentation for crwlr / crawler (v0.1)

Attention: You're currently viewing the documentation for v0.1 of the crawler package.
This is not the latest version of the package.
If you didn't navigate to this version intentionally, you can click here to switch to the latest version.

JSON Steps

The Json step has a get method that works pretty much like the extract method of the Html and Xml steps. Thanks to adbario/php-dot-notation extracting data from JSON documents is really simple:

use Crwlr\Crawler\Steps\Json;

Json::get([
    'foo' => 'data.target.foo',
    'bar' => 'data.target.array.1.baz',
]);

So, you provide an array with a name for the property as key and the dot notation string for the JSON property you want to get as value.

You can also extract multiple items by using the each method:

use Crwlr\Crawler\Steps\Json;

Json::each('list.people', ['name' => 'name', 'age' => 'age.years']);

So the first param in that call points to an array in the JSON document and the second is a mapping just as you provide it for the get method.