Download the PHP package evgeek/scraperapi-sdk without Composer
On this page you can find all versions of the php package evgeek/scraperapi-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download evgeek/scraperapi-sdk
More information about evgeek/scraperapi-sdk
Files in evgeek/scraperapi-sdk
Package scraperapi-sdk
Short Description SDK for scraperapi.com
License MIT
Homepage https://github.com/evgeek/scraperapi-sdk
Informations about the package scraperapi-sdk
PHP SDK for ScraperAPI
Simplify your web scrapping tasks with ScraperAPI. This SDK works with Guzzle client, providing asynchronous multithreading requests and convenient PSR-7 response.
Installation
Requires PHP version 7.2 or higher
Basic usage
Setup client
The client is configured through the constructor parameters:
- (required) - your API key from ScraperAPI dashboard.
-
- default API parameters for requests
-
- default HTTP headers
- (default ) - request timeout.
- (default ) - number of request attempts.
- (default ) - delay multiplier before new request attempt in seconds. Multiplier 3 means 2nd attempt will be in 3 sec, 3rd attempt in 6 sec, etc.
- (default ) - if true, debug messages will be printed. Useful for debugging async requests.
- (default ) - if false, API key in debug messages will be replaced by 'API_KEY' string.
- (default ) - PSR-3 compatible logger for debug messages. If null, they will be sent to the STDOUT.
- (default ) - log level for PSR-3 logger. If null, debug messages will be sent to the level.
- (default ) - maximum length of Guzzle exceptions messages.
Configure default SDK Client parameters
API parameters
Configuring default API functionality according to ScraperAPI documentation . The default settings apply to all requests, unless they are overridden at the request level. You can set the default options only from constructor (SDK client is immutable), using the second parameter:
Headers
You can add default headers with the third parameter of the constructor. Don't forget to enable to allow your headers to be used!
Requests
SDK supports , and HTTP methods. Standard parameters of each request methods:
- (required) - url of scrapped resource.
- (default ) - to set the API settings for the request. They will override the defaults from the SDK Client (only those that overlap).
- (default ) - to set headers for the request. Just like , they will override the defaults from the SDK Client (only those that overlap).
Synchronous
GET
Pretty simple:
POST/PUT
A bit more complicated:
You can use three types of payload:
- for raw , resource or .
-
- for form data . Associative of form field names to values where each value is a string or array of strings.
-
- for json. The passed associative will be automatically converted to json data.
There are also short forms of methods for different types of payloads:
By the way, it is convenient to pass the GraphQL payload through :
Asynchronous
Everything is similar to synchronous, but the work is going not through requests, but through promises:
Your ScraperAPI Account Information
You can get your ScraperAPI account information using the accountInfo()
method: