{"id":16675128,"url":"https://github.com/evgeek/scraperapi-sdk","last_synced_at":"2025-12-26T09:21:51.689Z","repository":{"id":56980154,"uuid":"436658001","full_name":"evgeek/scraperapi-sdk","owner":"evgeek","description":"SDK for web scrapping service ScraperAPI","archived":false,"fork":false,"pushed_at":"2022-01-19T14:32:08.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T21:47:23.927Z","etag":null,"topics":["php","scraper","scraperapi","scrapping","sdk","sdk-php","webscraper","webscrapping"],"latest_commit_sha":null,"homepage":"https://scraperapi.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evgeek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-09T15:02:35.000Z","updated_at":"2021-12-14T19:34:47.000Z","dependencies_parsed_at":"2022-08-21T10:50:25.140Z","dependency_job_id":null,"html_url":"https://github.com/evgeek/scraperapi-sdk","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgeek%2Fscraperapi-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgeek%2Fscraperapi-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgeek%2Fscraperapi-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgeek%2Fscraperapi-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evgeek","download_url":"https://codeload.github.com/evgeek/scraperapi-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243337889,"owners_count":20275374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","scraper","scraperapi","scrapping","sdk","sdk-php","webscraper","webscrapping"],"created_at":"2024-10-12T12:45:35.178Z","updated_at":"2025-12-26T09:21:51.664Z","avatar_url":"https://github.com/evgeek.png","language":"PHP","readme":"# PHP SDK for ScraperAPI\n\nSimplify your web scrapping tasks with [ScraperAPI](https://www.scraperapi.com/). This SDK works\nwith [Guzzle client](https://github.com/guzzle/guzzle), providing asynchronous multithreading requests and\nconvenient [PSR-7](https://www.php-fig.org/psr/psr-7/) response.\n\n## Installation\n\nRequires PHP version 7.2 or higher\n\n```bash\n$ composer require evgeek/scraperapi-sdk\n```\n\n## Basic usage\n\n```php\n\u003c?php\n\nuse Evgeek\\Scraperapi\\Client;\n\nrequire '/path/to/you/vendor/autoload.php';\n\n//Create and configure a new SDK client\n$sdk = new Client('YOUR_TOKEN');\n\n//Send request\n$response = $sdk-\u003eget('https://example.com');\n\n//Work with \\Psr\\Http\\Message\\ResponseInterface\necho $response-\u003egetBody()-\u003egetContents();\n```\n\n## Setup client\n\nThe client is configured through the constructor parameters:\n\n* ```$apiKey``` (required) - your API key from [ScraperAPI dashboard](https://dashboard.scraperapi.com/dashboard).\n* ```$defaultApiParams``` - default API parameters for requests\n* ```$defaultHeaders``` - default HTTP headers\n* ```$timeout``` (default ```60```) - request timeout.\n* ```$tries```  (default ```3```) - number of request attempts.\n* ```$delayMultiplier```  (default ```1```) - delay multiplier before new request attempt in seconds. Multiplier 3 means\n  2nd attempt will be in 3 sec, 3rd attempt in 6 sec, etc.\n* ```$printDebugInfo```  (default ```false```) - if true, debug messages will be printed. Useful for debugging async\n  requests.\n* ```$showApiKey```  (default ```false```) - if false, API key in debug messages will be replaced by 'API_KEY' string.\n* ```$logger``` (default ```null```) - [PSR-3](https://www.php-fig.org/psr/psr-3/) compatible logger for debug messages.\n  If null, they will be sent to the STDOUT.\n* ```$logLevel``` (default ```null```) - log level for [PSR-3](https://www.php-fig.org/psr/psr-3/) logger. If null,\n  debug messages will be sent to the ```DEBUG``` level.\n* ```$maxExceptionsLength``` (default ```120```) - maximum length of Guzzle exceptions messages.\n\n## Configure default SDK Client parameters\n\n### API parameters\n\nConfiguring default API functionality according to [ScraperAPI documentation](https://www.scraperapi.com/documentation/)\n. The default settings apply to all requests, unless they are overridden at the request level. You can set the default\noptions only from constructor (SDK client is immutable), using the second parameter:\n\n```php\n$defaultApiParams = [\n    'country_code' =\u003e 'us', //activate country geotargetting\n    'render' =\u003e true, //activate javascript rendering\n    'premium' =\u003e false, //activate premium residential and mobile IPs\n    'session_number' =\u003e 123, //reuse the same proxy\n    'keep_headers' =\u003e true, //use your own custom headers\n    'device_type' =\u003e 'mobile', //set mobile or desktop user agents\n    'autoparse' =\u003e 'false', //activate auto parsing for select websites\n];\n$sdk = new Client('YOU_TOKEN', $defaultApiParams);\n```\n\n### Headers\n\nYou can add default headers with the third parameter of the constructor. Don't forget to enable ```keep_headers``` to\nallow your headers to be used!\n\n```php\n$defaultHeaders = [\n    'Referer' =\u003e 'https://example.com/',\n    'Accept' =\u003e 'application/json',\n];\n$sdk = new Client('YOU_TOKEN', ['keep_headers' =\u003e true], $defaultHeaders);\n```\n\n## Requests\n\nSDK supports ```GET```, ```POST``` and ```PUT``` HTTP methods. Standard parameters of each request methods:\n\n1. ```$url``` (required) - url of scrapped resource.\n2. ```$apiParams``` (default ```null```) - to set the API settings for the request. They will override the defaults from\n   the SDK Client (only those that overlap).\n3. ```$headers``` (default ```null```) - to set headers for the request. Just like ```$apiParams```, they will override\n   the defaults from the SDK Client (only those that overlap).\n\n### Synchronous\n\n#### GET\n\nPretty simple:\n\n```php\n$response = $sdk-\u003eget(\n    'https://example.com', \n    ['keep_headers' =\u003e true], \n    [\n        'Referer' =\u003e 'https://example.com/',\n        'Accept' =\u003e 'application/json',\n    ]\n);\n$content = $response-\u003egetBody()-\u003egetContents();\n```\n\n#### POST/PUT\n\nA bit more complicated:\n\n```php\n$response = $sdk-\u003epost('https://example.com', $apiParams, $headers, $body, $formParams, $json);\n$content = $response-\u003egetBody()-\u003egetContents();\n```\n\nYou can use three types of payload:\n\n* ```$body``` for raw ```string```, ```fopen()``` resource or ```Psr\\Http\\Message\\StreamInterface```.\n* ```$formParams``` - for form data . Associative ```array``` of form field names to values where each value is a string\n  or array of strings.\n* ```$json``` - for json. The passed associative ```array``` will be automatically converted to json data.\n\nThere are also short forms of methods for different types of payloads:\n```php\n$response = $sdk-\u003epostBody($url, $body, $apiParams, $headers);\n$response = $sdk-\u003epostForm($url, $formParams, $apiParams, $headers);\n$response = $sdk-\u003epostJson($url, $json, $apiParams, $headers);\n```\n\nBy the way, it is convenient to pass the GraphQL payload through ```$json```:\n\n```php\n$query = '\n    query HeroNameAndFriends($episode: Episode) {\n      hero(episode: $episode) {\n        name\n        friends {\n          name\n        }\n      }\n    }\n';\n$json = ['query' =\u003e $query, 'variables' =\u003e ['episode' =\u003e 'JEDI']];\n\n$response = $sdk-\u003epostJson('https://example.com', $json);\n```\n\n### Asynchronous\n\nEverything is similar to synchronous, but the work is going not through requests, but through promises:\n\n```php\n//Create array with promises\n$promises = [\n    'first' =\u003e $sdk-\u003egetPromise('https://example.com', ['country_code' =\u003e 'us']),\n    'second' =\u003e $sdk-\u003epostPromiseBody('https://example.com', 'payload'),\n];\n//Asynchronous fulfillment of promises\n$responses = $sdk-\u003eresolvePromises($promises);\n\n//Work with array of responses\nforeach ($responses as $response) {\n    echo $response-\u003egetBody()-\u003egetContents() . PHP_EOL;\n}\n```\n\n## Your ScraperAPI Account Information\n\nYou can get your ScraperAPI account information using the ``accountInfo()`` method:\n\n```php\n$info = $sdk-\u003eaccountInfo();\nvar_dump(json_decode($info, true));\n```\n\n```\narray(5) {\n  [\"concurrencyLimit\"]=\u003e\n  int(5)\n  [\"concurrentRequests\"]=\u003e\n  int(0)\n  [\"failedRequestCount\"]=\u003e\n  int(258)\n  [\"requestCount\"]=\u003e\n  int(588)\n  [\"requestLimit\"]=\u003e\n  string(4) \"1000\"\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgeek%2Fscraperapi-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevgeek%2Fscraperapi-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgeek%2Fscraperapi-sdk/lists"}