Download the PHP package glook/apist without Composer
On this page you can find all versions of the php package glook/apist. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package apist
Short Description Package to provide api-like access to foreign sites based on html parsing (fork of sleeping-owl/apist package with updated dependencies)
License MIT
Homepage https://github.com/glook/apist
Informations about the package apist
Glook Apist
Fork of sleeping-owl/apist with updated dependencies.
Glook Apist is a small library which allows you to access any site in api-like style, based on html parsing.
Install the Package
From Packagist:
Usage
Basic example
Create a class that extends Apist and define your API methods using blueprints — arrays that map keys to CSS selectors
with extraction chains:
Result:
Blueprint concept
A blueprint is an array (or a single selector) that describes how to extract structured data from HTML. Each value
in the blueprint is an ApistSelector — a chain of CSS selector + extraction methods.
Static helpers
Apist::filter('.selector')— creates anApistSelectorbound to a CSS selectorApist::current()— references the current element insideeach()iterations
HTTP methods
All standard HTTP methods are supported:
The $options array is passed directly to Guzzle's request options.
Filter methods
Extraction methods available in selector chains:
| Method | Description |
|---|---|
text() |
Get text content |
html() |
Get inner HTML |
attr('name') |
Get attribute value |
hasAttr('name') |
Check if attribute exists |
exists() |
Check if element exists |
Navigation:
| Method | Description |
|---|---|
first() |
First matched element |
last() |
Last matched element |
eq($index) |
Element at index |
next() |
Next sibling |
prev() |
Previous sibling |
children() |
Child elements |
closest($selector) |
Closest ancestor matching selector |
Iteration:
| Method | Description |
|---|---|
each($blueprint) |
Iterate over matched elements |
each() |
Returns collection for chaining |
Transformation:
| Method | Description |
|---|---|
call($callback) |
Apply custom callback |
check($condition, $then) |
Conditional logic |
then($blueprint) |
Apply blueprint if truthy |
trim() |
Trim whitespace |
intval() |
Cast to integer |
floatval() |
Cast to float |
str_replace($search, $replace) |
String replacement |
mb_substr($start, $length) |
Multibyte substring |
Any global PHP function can also be used in the chain (e.g., strtoupper, strip_tags).
Error handling
By default, HTTP errors are suppressed and returned as structured error responses:
Access to Guzzle response
After a request, you can access the underlying Guzzle response:
Testing
Supported PHP Versions
That package has been tested on the following PHP versions:
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
Copyright and License
Originally written by Sleeping Owl and released under the MIT License.
Fork maintained by Andrey Polyakov.
See the LICENSE file for details.
All versions of apist with dependencies
guzzlehttp/guzzle Version ^7.10.0
symfony/css-selector Version ^5.4.45
symfony/dom-crawler Version ^5.4.48