Get started scraping the web in as little as 2 minutes
Using ScraperAPI is easy. Just send the URL you would like to scrape to the API along with your API key and the API will return the HTML response from the URL you want to scrape.
ScraperAPI uses API keys to authenticate requests. To use the API you need to sign up for an account and include your unique API key in every request.
If you haven’t signed up for an account yet then sign up for a free trial here with 5,000 free API credits!
You can use the API to scrape web pages, API endpoints, images, documents, PDFs, or other files just as you would any other URL. Note: there is a 2MB limit per request.
There are five ways in which you can send GET requests to ScraperAPI:
http://async.scraperapi.com
http://api.scraperapi.com?
http://scraperapi:APIKEY@proxy-server.scraperapi.com:8001
https://api.scraperapi.com/structured/
Choose whichever option best suits your scraping requirements.
Important note: regardless of how you invoke the service, we highly recommend you set a 60 seconds timeout in your application to get the best possible success rates, especially for some hard-to-scrape domains.
To ensure a higher level of successful requests when using our scraper, we’ve built a new product, Async Scraper. Rather than making requests to our endpoint waiting for the response, this endpoint submits a job of scraping, in which you can later collect the data from using our status endpoint.
Scraping websites can be a difficult process; it takes numerous steps and significant effort to get through some sites’ protection which sometimes proves to be difficult with the timeout constraints of synchronous APIs. The Async Scraper will work on your requested URLs until we have achieved a 100% success rate (when applicable), returning the data to you.
Async Scraping is the recommended way to scrape pages when success rate on difficult sites is more important to you than response time (e.g. you need a set of data periodically).
The async scraper endpoint is available at https://async.scraperapi.com
and it exposes a few useful APIs.
A simple example showing how to submit a job for scraping and receive a status endpoint URL through which you can poll for the status (and later the result) of your scraping job:
<?php
$payload = json_encode(
array(
"apiKey"
=>
"xxxxxx",
"url"
=>
"https://example.com"
) ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,
"https://async.scraperapi.com/jobs"
); curl_setOpt( $ch, CURLOPT_POST,
1
); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER,
array(
"Content-Type:application/json"
) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,
TRUE
); $response = curl_exec( $ch ); curl_close( $ch ); print_r( $response );
You can also send POST requests to the Async scraper now. To make this possible, you will need to use the parameter “method”: “POST”. Here is an example on how to make a POST request to the Async scraper:
<?php
$payload = json_encode(
array(
"apiKey"
=>
"xxxxxx",
"method"
=>
"POST",
"body"
=>
"var1=value1&var2=value2",
"url"
=>
"https://example.com"
) ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,
"https://async.scraperapi.com/jobs"
); curl_setOpt( $ch, CURLOPT_POST,
1
); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER,
array(
"Content-Type:application/json"
) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,
TRUE
); $response = curl_exec( $ch ); curl_close( $ch ); print_r( $response );
Response:
{
"id":"0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"status":"running",
"statusUrl":"https://async.scraperapi.com/jobs/0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"url":"https://example.com"
}
Note the statusUrl
field in the response. That is a personal URL to retrieve the status and results of your scraping job. Invoking that endpoint provides you with the status first:
<?php
$ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,
"https://async.scraperapi.com/jobs/0962a8e0-5f1a-4e14-bf8c-5efcc18f0953"
); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,
TRUE
); $response = curl_exec( $ch ); curl_close( $ch ); print_r( $response );
Response:
{
"id":"0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"status":"running",
"statusUrl":"https://async.scraperapi.com/jobs/0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"url":"https://example.com"
}
Once your job is finished, the response will change and will contain the results of your scraping job:
{
"id":"0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"status":"finished",
"statusUrl":"https://async.scraperapi.com/jobs/0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"url":"https://example.com",
"response":{
"headers":{
"date":"Thu, 14 Apr 2022 11:10:44 GMT",
"content-type":"text/html; charset=utf-8",
"content-length":"1256",
"connection":"close",
"x-powered-by":"Express",
"access-control-allow-origin":"undefined","access-control-allow-headers":"Origin, X-Requested-With, Content-Type, Accept",
"access-control-allow-methods":"HEAD,GET,POST,DELETE,OPTIONS,PUT",
"access-control-allow-credentials":"true",
"x-robots-tag":"none",
"sa-final-url":"https://example.com/",
"sa-statuscode":"200",
"etag":"W/\"4e8-Sjzo7hHgkd15I/TYxuW15B7HwEc\"",
"vary":"Accept-Encoding"
},
"body":"<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.</p>\n <p><a href=\"https://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n",
"statusCode":200
} }
Please note that the response of an Async job is stored for up to 4 hours or until you retrieve the results, whichever comes first.. If you do not get the response in due time, it will be deleted from our side and you will have to send another request for the same job.
Using a status URL is a great way to test the API or get started quickly, but some customer environments may require some more robust solutions, so we implemented callbacks. Currently only webhook
callbacks are supported but we are planning to introduce more over time (e.g. direct database callbacks, AWS S3, etc).
An example of using a webhook callback:
<?php
$payload = json_encode(
array(
"apiKey"
=>
"xxxxxx",
"callback"
=>
array(
"type"
=>
"webhook",
"url"
=>
"https://yourcompany.com/scraperapi"
),
"url"
=>
"https://example.com"
) ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,
"https://async.scraperapi.com/jobs"
); curl_setOpt( $ch, CURLOPT_POST,
1
); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER,
array(
"Content-Type:application/json"
) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,
TRUE
); $response = curl_exec( $ch ); curl_close( $ch ); print_r( $response );
Using a callback you don’t need to use the status URL (although you still can) to fetch the status and results of the job. Once the job is finished the provided webhook URL will be invoked by our system with the same content as the status URL provides.
Just replace the https://yourcompany.com/scraperapi
URL with your preferred endpoint. You can even add basic auth to the URL in the following format: https://user:pass@yourcompany.com/scraperapi
Note: The system will try to invoke the webhook URL 3 times, then it cancels the job. So please make sure that the webhook URL is available through the public internet and will be capable of handling the traffic that you need.
Hint: Webhook.site is a free online service to test webhooks without requiring you to build a complex infrastructure.
You can use the usual API parameters just the same way you’d use it with our synchronous API. These parameters should go into an apiParams
object inside the POST data, e.g:
{
"apiKey":
"xxxxxx",
"apiParams": {
"autoparse":
false,
// boolean
"binary_target":
false,
// boolean
"country_code":
"us",
// string, see: https://api.scraperapi.com/geo
"device_type":
"desktop",
// desktop | mobile
"follow_redirect":
false,
// boolean
"premium":
true,
// boolean
"render":
false,
// boolean
"retry_404":
false
// boolean
},
"url":
"https://example.com"
}
We have created a separate endpoint that accepts an array of URLs instead of just one to initiate scraping of multiple URLs at the same time: https://async.scraperapi.com/batchjobs. The API is almost the same as the single endpoint, but we expect an array of strings in the urls field instead of a string in url.
<?php
$payload = json_encode(
array(
"apiKey"
=>
"xxxxxx",
"urls"
=>
("https://example.com/page1", "https://example.com/page2")
) ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,
"https://async.scraperapi.com/batchjobs"
); curl_setOpt( $ch, CURLOPT_POST,
1
); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER,
array(
"Content-Type:application/json"
) ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER,
TRUE
); $response = curl_exec( $ch ); curl_close( $ch ); print_r( $response );
As a response you’ll also get an array of the same response that you get using our single job endpoint:
[
{
"id":"0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"status":"running",
"statusUrl":"https://async.scraperapi.com/jobs/0962a8e0-5f1a-4e14-bf8c-5efcc18f0953",
"url":"https://example.com/page1"
}
{
"id":"238d54a1-62af-41a9-b0b4-63f240bad439",
"status":"running",
"statusUrl":"https://async.scraperapi.com/jobs/238d54a1-62af-41a9-b0b4-63f240bad439",
"url":"https://example.com/page2"
}
]
ScraperAPI exposes a single API endpoint for you to send GET requests. Simply send a GET request to http://api.scraperapi.com
with two query string parameters and the API will return the HTML response for that URL:
api_key
which contains your API key, andurl
which contains the url you would like to scrapeYou should format your requests to the API endpoint as follows:
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip"
Sample Code
<?php
$url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
To enable other API functionality when sending a request to the API endpoint simply add the appropriate query parameters to the end of the ScraperAPI URL.
For example, if you want to enable Javascript rendering with a request, then add render=true
to the request:
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true"
Sample Code
<?php
$url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
To use two or more parameters, simply separate them with the “&” sign.
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true&country_code=us"
Sample Code
<?php
$url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true&country_code=us"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
To make it easier to get up and running you can also use our Python SDK. First, you will need to install the SDK:
gem install scraperapi
Then integrate it into your code:
Sample Code
# remember to install the library: composer require scraperapi/sdk
<?php
$client =
new
ScraperAPI\Client("APIKEY"); $result = $client->get("http://httpbin.org/ip")->raw_body;
print($result);
To enable extra functionality while using our SDK, simply add an additional parameter to the GET request:
# remember to install the library: composer require scraperapi/sdk
<?php
$client =
new
ScraperAPI\Client("APIKEY"); $result = $client->get("http://httpbin.org/ip", ["render"
=>
true])->raw_body;
print($result);
To use two or more parameters, simply add them to the GET request:
# remember to install the library: composer require scraperapi/sdk
<?php
$client =
new
ScraperAPI\Client("APIKEY"); $result = $client->get("http://httpbin.org/ip", ["render"
=>
true], [“country_code” => “us”])->raw_body;
print($result);
To simplify implementation for users with existing proxy pools, we offer a proxy front-end to the API. The proxy will take your requests and pass them through to the API which will take care of proxy rotation, captchas, and retries.
The proxy mode is a light frontend for the API and has all the same functionality and performance as sending requests to the API endpoint.
The username
for the proxy is scraperapi and the password
is your API key.
"http://scraperapi:APIKEY@proxy-server.scraperapi.com:8001"
You can use the ScraperAPI proxy the same way as you would use any other proxy:
<?php
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL,
"http://httpbin.org/ip"); curl_setopt($ch, CURLOPT_PROXY,
"http://scraperapi:APIKEY@proxy-server.scraperapi.com:8001"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); var_dump($response);
Note: So that we can properly directly your requests through the API, your code must be configured to not verify SSL certificates.
To enable extra functionality whilst using the API in proxy mode, you can pass parameters to the API by adding them to username, separated by periods.
For example, if you want to enable Javascript rendering with a request, the username would be scraperapi.render=true
"http://scraperapi.render=true:APIKEY@proxy-server.scraperapi.com:8001"
Multiple parameters can be included by separating them with periods; for example:
"http://scraperapi.render=true.country_code=us:APIKEY@proxy-server.scraperapi.com:8001"
To make it even easier to get structured content, we created custom endpoints within our API that provide a shorthand method of retrieving content from supported domains. This method is ideal for users that need to receive data in JSON and also need an easy way to construct the URLs they need to scrape.
This endpoint will retrieve product data from an Amazon product page and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/amazon/product?api_key=APIKEY&asin=ASIN&country=COUNTRY&tld=TLD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code above, you can use several parameters with this method:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
ASIN |
Amazon product ASIN |
COUNTRY |
Where an amazon domain needs to be scraped from another country (e.g. scraping amazon.com from Canada to get Canadian shipping information), specify the TLD as well as the COUNTRY parameters. Valid values are valid TLDs (e.g. “.com.au”, “.es”, etc.) Valid values include:
us: 'amazon.com', uk: 'amazon.co.uk', ca: 'amazon.ca', de: 'amazon.de', es: 'amazon.es', fr: 'amazon.fr', it: 'amazon.it', jp: 'amazon.co.jp', in: 'amazon.in', cn: 'amazon.cn', sg: 'amazon.com.sg', mx: 'amazon.com.mx', ae: 'amazon.ae', br: 'amazon.com.br', nl: 'amazon.nl', au: 'amazon.com.au', tr: 'amazon.com.tr', sa: 'amazon.sa', se: 'amazon.se', pl: 'amazon.pl' |
TLD |
Country of Amazon domain to scrape. This is an optional argument and defaults to “us” (amazon.com). |
Sample Response:
{
"name": "Animal Adventure | Sweet Seats | Pink Owl Children's Plush Chair",
"product_information": {
"product_dimensions": "14 x 19 x 20 inches",
"color": "Pink",
"material": "95% Polyurethane Foam, 5% Polyester Fibers",
"style": "Pink Owl",
"product_care_instructions": "Machine Wash",
"number_of_items": "1",
"brand": "Animal Adventure",
"fabric_type": "Polyurethane",
"unit_count": "1.0 Count",
"item_weight": "1.9 pounds",
"asin": "B06X3WKY59",
"item_model_number": "49559",
"manufacturer_recommended_age": "18 months - 4 years",
"best_sellers_rank": [
"#9,307 in Home & Kitchen (See Top 100 in Home & Kitchen)",
"#69 in Kids' Furniture"
],
"customer_reviews": {
"ratings_count": 5665,
"stars": "4.7 out of 5 stars"
},
"is_discontinued_by_manufacturer": "No",
"release_date": "January 1, 2018",
"manufacturer": "Animal Adventure"
},
"brand": "Visit the Animal Adventure Store",
"brand_url": "https://www.amazon.com/stores/AnimalAdventure/page/8871D37C-D748-4489-8FBA-8D6A62092857?ref_=ast_bln",
"full_description": "Our Sweet Seats character chairs double as adorable room décor and a child’s favorite plush pal. Rich fabrics, sweet dimensional faces and a soft yet sturdy design make these character chairs ideal for kids 18 months +, and parents will be thrilled to learn that they can easily wash and care for their child’s new favorite seat. WASHING INSTRUCTIONS: Simply take a paper clip, hook through the safety zipper and pull to open the character chair cover. Carefully cut the tack stitch thread that secures the cover to the center foam block with a pair of scissors. Once all tacks have been cut, you can remove the foam blocks. Once you’ve removed all of the inner foam pieces, your cover is ready to wash. For best results, we recommend using a delicates bag in a machine wash cold setting, and afterwards laying the cover flat to air dry.",
"pricing": "",
"list_price": "",
"shipping_price": null,
"availability_status": "",
"images": [
"https://m.media-amazon.com/images/I/51RzYQSm5oL.jpg",
"https://m.media-amazon.com/images/I/416w6PJNGWL.jpg",
"https://m.media-amazon.com/images/I/51vmBiGcqNL.jpg",
"https://m.media-amazon.com/images/I/51Zm4EdynxL.jpg",
"https://m.media-amazon.com/images/I/510JJx9LuiL.jpg",
"https://m.media-amazon.com/images/I/51JwT+-IwnL.jpg"
],
"product_category": "Home & Kitchen › Furniture › Kids' Furniture",
"average_rating": 4.7,
"small_description": "About this item \n \nPolyurethane Imported Plush slip cover is removable and washable. Zipper closure is child-safe (parents can easily open closer with a simple paper clip). Lightweight and easy to move. The perfect size (14\"L x 19\"W x 20\"H). Ages 18 months and up.",
"feature_bullets": [
"Polyurethane",
"Imported",
"Plush slip cover is removable and washable.",
"Zipper closure is child-safe (parents can easily open closer with a simple paper clip).",
"Lightweight and easy to move.",
"The perfect size (14\"L x 19\"W x 20\"H).",
"Ages 18 months and up."
],
"total_reviews": 5665,
"total_answered_questions": 111,
"model": "49559",
"customization_options": {
"style": [
{
"is_selected": true,
"url": null,
"value": "Pink Owl",
"price_string": "",
"price": 0,
"image": null
},
{
"is_selected": false,
"url": "https://www.amazon.com/dp/B0731Y59HG/ref=twister_B0B9FV38F9?_encoding=UTF8&psc=1",
"value": "Teal Owl",
"price_string": "",
"price": 0,
"image": null
}
]
},
"seller_id": null,
"seller_name": null,
"fulfilled_by_amazon": null,
"fast_track_message": "",
"aplus_present": true
}
This endpoint will retrieve products for a specified search term from Amazon search page and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/amazon/search?api_key=APIKEY&query=QUERY&country=COUNTRY&tld=TLD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code abode, you can use several parameters with this method as well:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
query |
Amazon Search query string |
COUNTRY |
Where an amazon domain needs to be scraped from another country (e.g. scraping amazon.com from Canada to get Canadian shipping information), specify the TLD as well as the COUNTRY parameters. Valid values are valid TLDs (e.g. “.com.au”, “.es”, etc.). Valid values include:
us: 'amazon.com', uk: 'amazon.co.uk', ca: 'amazon.ca', de: 'amazon.de', es: 'amazon.es', fr: 'amazon.fr', it: 'amazon.it', jp: 'amazon.co.jp', in: 'amazon.in', cn: 'amazon.cn', sg: 'amazon.com.sg', mx: 'amazon.com.mx', ae: 'amazon.ae', br: 'amazon.com.br', nl: 'amazon.nl', au: 'amazon.com.au', tr: 'amazon.com.tr', sa: 'amazon.sa', se: 'amazon.se', pl: 'amazon.pl' |
TLD |
Country of Amazon domain to scrape. This is an optional argument and defaults to “us” (amazon.com). |
This endpoint will retrieve product data from an Google search result page and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/google/search?api_key=API_KEY&query=QUERY&country_code=COUNTRY_CODE&tld=TLD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
The Google Structured Data endpoint supports several parameters:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
QUERY |
Query keywords that a user wants to search for |
COUNTRY_CODE |
Where a google domain needs to be scraped from another country (e.g. scraping google.com from Canada to get Canadian results), specify the TLD as well as the COUNTRY_CODE parameters. Valid values are valid TLDs (e.g. “.com.au”, “.es”, etc.). |
TLD |
Country of Google domain to scrape. This is an optional argument and defaults to “us” (google.com). Valid values include:
us: 'google.com', uk: 'google.co.uk', ca: 'google.ca', de: 'google.de', es: 'google.es', fr: 'google.fr', it: 'google.it', jp: 'google.co.jp', in: 'google.in', cn: 'google.cn', sg: 'google.com.sg', mx: 'google.com.mx', ae: 'google.ae', br: 'google.com.br', nl: 'google.nl', au: 'google.com.au', tr: 'google.com.tr', sa: 'google.sa', se: 'google.se', pl: 'google.pl' |
Google parameters |
We also support Google Search parameters for this endpoint. Examples:
UULE: Set a region for a search. For example: w+CAIQICINUGFyaXMsIEZyYW5jZQ. You can find an online UULE generator here: https://site-analyzer.pro/services-seo/uule/ NUM: Number of results HL: Host Language. For example: DE GL: Boosts matches whose country of origin matches the parameter value. For example: DE IE: Character encoding how the engine interpret the query string. For example: UTF8 OE: Character encoding used for the results. For example: UTF8 START: Set the starting offset in the result list. When start=10 set the first element in the result list will be the 10th search result (meaning it starts with page 2 of results if the "num" is 10) |
This endpoint will retrieve information available for a twitter search and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/search?api_key=APIKEY&query=TWITTER_QUERY&next_cursor=NEXT_CURSOR_VALUE"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code above, you can use several parameters with this method:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
query |
Twitter query link |
next_cursor |
If provided, the result will show the next page compared to the page the next cursor was found |
This endpoint will retrieve information available for a twitter profile and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/profile?api_key=APIKEY&user=TWITTER_USER"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code above, you can use several parameters with this method:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
user |
Twitter username. Example: elonmusk |
This endpoint will retrieve tweets for a given twitter profile. and transform it into usable JSON. There 3 possible endpoints to scrape user's tweets, replies or media.
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/tweets?api_key=APIKEY&user_id=TWITTER_USERID&next_cursor=NEXT_CURSOR_VALUE"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/replies?api_key=APIKEY&user_id=TWITTER_USERID&next_cursor=NEXT_CURSOR_VALUE"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/media?api_key=APIKEY&user_id=TWITTER_USERID&next_cursor=NEXT_CURSOR_VALUE"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code above, you need to use 2 parameters with this method:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
user_id |
Twitter user_id for example: 44196397 |
next_cursor |
If provided, the result will show the next page compared to the page the next cursor was found |
This endpoint will retrieve information available for an individual tweet and transform it into usable JSON.
<?php
$url =
"https://api.scraperapi.com/structured/twitter/v2/tweet?api_key=APIKEY&tweet_id=TWEET_ID"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
As you can see in the code above, you can use several parameters with this method:
Parameter | Details |
---|---|
API_KEY |
User's normal API Key |
tweet_id |
Twitter tweet id. Example: 1659997938465091584 |
Some advanced users may want to send POST/PUT requests in order to scrape forms and API endpoints directly. You can do this by sending a POST/PUT request through ScraperAPI. The return value will be stringified. So if you want to use it as JSON, you will need to parse it into a JSON object.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/anything";
# POST/PUT Requests
$postData = ["foo"
=>
"bar"]; $postData = json_encode($postData); $headers = [
"Content-Type: application/json"
]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST,
1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
//Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close($ch); print_r($response);
#Form POST Request
$postData = ["foo"
=>
"bar"]; $postData = json_encode($postData); $headers = [
'Content-Type: application/x-www-form-urlencoded; charset=utf-8', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST,
true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); curl_close($ch); print_r($response);
ScraperAPI enables you to customize the API’s functionality by adding additional parameters to your requests. The API will accept the following parameters:
Parameter | Description |
---|---|
render
|
Activate javascript rendering by setting
render=true
in your request. The API will automatically render the javascript on the page and return the HTML response after the javascript has been rendered.
Requests using this parameter cost 10 API credits, or 75 if used in combination with ultra-premium
|
country_code
|
Activate country geotargeting by setting
country_code=us
to use US proxies for example.
This parameter does not increase the cost of the API request. |
premium
|
Activate premium residential and mobile IPs by setting
premium=true . Using premium proxies costs 10 API credits, or 25 API credits if used in combination with Javascript rendering
render=true . |
session_number
|
Reuse the same proxy by setting
session_number=123
for example.
This parameter does not increase the cost of the API request. |
binary_target |
Helpful when trying to scrape files or images. This tells our API that the target is a file. |
keep_headers
|
Use your own custom headers by setting
keep_headers=true
along with sending your own headers to the API.
This parameter does not increase the cost of the API request. |
device_type
|
Set your requests to use mobile or desktop user agents by setting
device_type=desktop
or
device_type=mobile .
This parameter does not increase the cost of the API request. |
autoparse
|
Activate auto parsing for select websites by setting
autoparse=true . The API will parse the data on the page and return it in JSON format.
This parameter does not increase the cost of the API request. |
ultra_premium
|
Activate our advanced bypass mechanisms by setting
ultra_premium=true .
Requests using this parameter cost 30 API credits, or 75 if used in combination with javascript rendering. |
If you are crawling a page that requires you to render the javascript on the page to scrape the data you need, then we can fetch these pages using a headless browser. To render javascript, simply set render=true
and we will use a headless Google Chrome instance to fetch the page. This feature is available on all plans.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&render=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
If a rendered request is a bit slow and the page stabilises before the request is satisfied, it can fool the API into thinking the page has finished rendering.
To cope with this, you can tell the API to wait for a dom element (selector) to appear on the page when rendering. You just need to send the wait_for_selector=
parameter, passing a URL-encoded jquery selector. The API will then wait for this to appear on the page before returning results.
If you would like to use your own custom headers (user agents, cookies, etc.) when making a request to the website, simply set keep_headers=true
and send the API the headers you want to use. The API will then use these headers when sending requests to the website.
Note: Only use this feature if you need to send custom headers to retrieve specific results from the website. Within the API we have a sophisticated header management system designed to increase success rates and performance on difficult sites. When you send your own custom headers you override our header system, which oftentimes lowers your success rates. Unless you absolutely need to send custom headers to get the data you need, we advise that you don’t use this functionality.
If you need to get results for mobile devices, use the device_type
parameter to set the user-agent header for your request, instead of setting your own.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&keep_headers=true"; $headerArray =
array(
"Content-Type: application/json",
"X-MyHeader: 123"
); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
Certain websites (typically e-commerce stores and search engines) display different data to different users based on the geolocation of the IP used to make the request to the website. In cases like these, you can use the API’s geotargeting functionality to easily use proxies from the required country to retrieve the correct data from the website.
To control the geolocation of the IP used to make the request, simply set thecountry_code
parameter to the country you want the proxy to be from and the API will automatically use the correct IP for that request.
For example: to ensure your requests come from the United States, set thecountry_code
parameter tocountry_code=us
.
Business and Enterprise Plan users can geotarget their requests to the following 13 regions (Hobby and Startup Plans can only use US and EU geotargeting) by using the country_code
in their request:
Country Code | Region | Plans |
---|---|---|
us
|
United States | Hobby Plan and higher. |
eu
|
Europe | Hobby Plan and higher. |
ca
|
Canada | Business Plan and higher. |
uk
|
United Kingdom | Business Plan and higher. |
de
|
Germany | Business Plan and higher. |
fr
|
France | Business Plan and higher. |
es
|
Spain | Business Plan and higher. |
br
|
Brazil | Business Plan and higher. |
mx
|
Mexico | Business Plan and higher. |
in
|
India | Business Plan and higher. |
jp
|
Japan | Business Plan and higher. |
cn
|
China | Business Plan and higher. |
au
|
Australia | Business Plan and higher. |
Geotargeting "eu" will use IPs from any European country.
Other countries are available to Enterprise customers uponrequest.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&country_code=us"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
To reuse the same proxy for multiple requests, simply use the session_number
parameter by setting it equal to a unique integer for every session you want to maintain (e.g. session_number=123
). This will allow you to continue using the same proxy for each request with that session number. To create a new session simply set the session_number
parameter with a new integer to the API. The session value can be any integer. Sessions expire 15 minutes after the last usage.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&session_number=123"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
Our standard proxy pools include millions of proxies from over a dozen ISPs and should be sufficient for the vast majority of scraping jobs. However, for a few particularly difficult to scrape sites, we also maintain a private internal pool of residential and mobile IPs. This pool is available to all paid users.
Requests through our premium residential and mobile pool are charged at 10 times the normal rate (every successful request will count as 10 API credits against your monthly limit). Each request that uses both javascript rendering and our premium proxy pools will be charged at 25 times the normal rate (every successful request will count as 25 API credits against your monthly limit). To send a request through our premium proxy pool, please set the premium
query parameter to premium=true
.
We also have a higher premium level that you can use for really tough targets, such as LinkedIn. You can access these pools by adding the ultra_premium=true
query parameter. These requests will use 30 API credits against your monthly limit, or 75 if used together with rendering. Please note this is only available on our paid plans.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&premium=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
Learn more about our rotating proxy and residential proxy solution.
If your use case requires you to exclusively use either desktop or mobile user agents in the headers it sends to the website then you can use the device_type
parameter.
device_type=desktop
to have the API set a desktop (e.g. iOS, Windows, or Linux) user agent. Note:
This is the default behavior. Not setting the parameter will have the same effect.device_type=mobile
to have the API set a mobile (e.g. iPhone or Android) user agent.Note: The device type you set will be overridden if you use keep_headers=true
and send your own user agent in the requests header.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&device_type=mobile"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
Every time you make a request, you consume credits. The credits you have available are defined by the plan you are currently using. The amount of credits you consume depends on the domain and parameters you add to your request.
We have created custom scrapers to target these sites, if you scrape one of these domains you will activate this scraper and the credit cost will change.
Category | Normal | Ecommerce | SERP | Protected Domains |
---|---|---|---|---|
credit cost | 1 |
5 |
25 |
30 |
render | 10 |
15 |
35 |
40 |
premium | 10 |
10 |
35 |
40 |
premium + render | 20 |
25 |
45 |
50 |
ultra_premium | 30 |
30 |
55 |
60 |
ultra_premium + render | 75 |
75 |
75 |
75 |
Geotargeting is included in these credit costs.
If your domain does not fit in any category in the above list, it will cost 1
credit if no additional parameters are added.
According to your needs, you may want to access different features on our platform.
premium=true
– requests cost 10 credits
render=true
– requests cost 10 credits
premium=true
+ render=true
– requests cost 20 credits
ultra_premium=true
– requests cost 30 credits
ultra_premium=true
+ render=true
– requests cost 75 credits
In any requests, with or without these parameters, we will only charge for successful requests (200
and 404
status codes) and for requests that have been cancelled from your side before giving us enough time to finish them (50 seconds). If you run out of credits sooner than planned, you can renew your subscription early as explained in the next section – Dashboard.
The API will return a specific status code after every request depending on whether the request was successful, failed or some other error occurred. ScraperAPI will retry failed requests for up to 60 seconds to try and get a successful response from the target URL before responding with a 500
error indicating a failed request.
Note: To avoid timing out your request before the API has had a chance to complete all retries, remember to set your timeout to 60 seconds.
In cases where a request fails after 60 seconds of retrying, you will not be charged for the unsuccessful request (you are only charged for successful requests, 200
and 404
status codes).
Errors will inevitably occur so on your end make sure you catch these errors. You can configure your code to immediately retry the request and in most cases, it will be successful. If a request is consistently failing then check your request to make sure that it is configured correctly. Or if you are consistently getting bans messages from an anti-bot, then create a ticket with our support team and we will try to bypass this anti-bot for you.
If you receive a successful 200
status code response from the API but the response contains a CAPTCHA, please contact our support team and we will add it to our CAPTCHA detection database. Once included in our CAPTCHA database, the API will treat it as a ban in the future and automatically retry the request.
Below are the possible status codes you will receive:
Status Code | Details |
---|---|
200
|
Successful response |
404
|
Page requested does not exist. |
410
|
Page requested is no longer available. |
500
|
After retrying for 60 seconds, the API was unable to receive a successful response. |
429
|
You are sending requests too fast, and exceeding your concurrency limit. |
403
|
You have used up all your API credits. |
For select websites, the API will parse all the valuable data in the HTML response and return it in JSON format. To enable this feature, simply add autoparse=true
to your request and the API will parse the data for you. Currently, this feature works with Amazon, Google Search, and Google Shopping.
<?php $url =
"http://api.scraperapi.com?api_key=APIKEY&url=http://httpbin.org/ip&autoparse=true"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
The Dashboard shows you all the information so you can keep track of your usage. It is divided into Usage, Billing, Documentation, and links to contact us.
Usage
Here you will find your API key, sample codes, monitoring tools, and usage statistics such as credits used, concurrency, failed requests, your current plan, and the end date of your billing cycle.
Billing
In this section, you are able to see your current plan, the end date of the current billing cycle, as well as subscribe to another plan. This is also the right place to set or update your billing details, payment method, view your invoices, manage your subscription, or cancel it.
Here you can also renew your subscription early, in case you run out of API credits sooner than planned. This option will let you renew your subscription at an earlier date than planned, charging you for the subscription price and resetting your credits. If you find yourself using this option regularly, please reach out to us so we can find a plan that can accommodate the number of credits you need.
Documentation
This will direct you to our documentation – exactly where you are right now.
Contact Support
Direct link to reach out to our technical support team.
Contact Sales
Direct link to our sales team, for any subscription or billing-related inquiries.
If you would like to monitor your account usage and limits programmatically (how many concurrent requests you’re using, how many requests you’ve made, etc.) you may use the /account endpoint, which returns JSON.
Note: the requestCount
and failedRequestCount
numbers only refresh once every 15 seconds, while the concurrentRequests
number is available in real time.
<?php $url =
"http://api.scraperapi.com/account?api_key=APIKEY"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,
TRUE); curl_setopt($ch, CURLOPT_HEADER,
FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
0); $response = curl_exec($ch); curl_close($ch); print_r($response);
Get started with 5,000 free API credits or contact sales
No credit card required