SDKs overview
ScraperApi provides both official and community-developed Software Development Kits (SDKs) and libraries to facilitate integration with its web scraping API. These tools abstract away some of the complexities of direct HTTP requests, proxy management, and handling anti-bot measures, allowing developers to focus on data extraction logic. The primary function of ScraperApi is to route web scraping requests through a network of proxies, automatically handling retries, CAPTCHAs, and browser rendering for JavaScript-heavy sites ScraperApi documentation. The SDKs wrap these capabilities, offering language-specific methods and classes for common operations.
Integrating ScraperApi typically involves sending a URL to the API as a parameter. The API then fetches the content, processes it, and returns the HTML. SDKs simplify this interaction by providing objects or functions that construct these API requests and parse the responses. This can reduce boilerplate code and potential errors when setting up proxy configurations or managing request headers manually. For instance, ScraperApi's Python SDK provides a client that automatically appends API keys and handles URL encoding, as detailed in the ScraperApi Python SDK guide.
Official SDKs by language
ScraperApi maintains official SDKs for several popular programming languages, designed to offer direct integration and support for the API's features. These SDKs are typically kept up-to-date with API changes and are recommended for most development workflows. The official support covers a range of environments, from server-side applications to scripting tasks. Each SDK aims to provide a native-feeling interface within its respective language paradigm.
Below is a summary of the officially supported SDKs, including their package names, typical installation commands, and general maturity level:
| Language | Package Name | Installation Command (Example) | Maturity |
|---|---|---|---|
| Python | scraperapi-python |
pip install scraperapi |
Stable |
| Node.js | scraperapi |
npm install scraperapi |
Stable | _
| Ruby | scraperapi-ruby |
gem install scraperapi |
Maintained |
| PHP | scraperapi/scraperapi-php |
composer require scraperapi/scraperapi-php |
Maintained |
| Java | (No direct SDK, uses HTTP client) | (Add dependency for OkHttp/HttpClient) | HTTP Client focused |
| Go | (No direct SDK, uses HTTP client) | (Standard net/http library) |
HTTP Client focused |
While Python and Node.js have dedicated SDKs that abstract API calls, languages like Java and Go often rely on making direct HTTP requests with standard libraries or popular third-party HTTP clients. ScraperApi provides extensive code examples for these languages demonstrating how to construct the API URL and parse the JSON response ScraperApi Java integration example.
Installation
Installing ScraperApi SDKs and integrating the service involves adding the appropriate package to your project and then configuring it with your API key. The specific steps vary by programming language and package manager, but the fundamental process remains consistent.
Python
For Python projects, the scraperapi package can be installed using pip, Python's package installer PyPI pip documentation. After installation, you can import the client and initialize it with your API key.
pip install scraperapi
After installation, the SDK can be accessed in your Python scripts:
from scraperapi import ScraperAPIClient
client = ScraperAPIClient('YOUR_API_KEY')
Node.js
Node.js developers can install the scraperapi package via npm, the default package manager for Node.js npm documentation. This provides access to a client library for sending requests.
npm install scraperapi
To use the client in your Node.js application:
const ScraperAPIClient = require('scraperapi')();
const client = new ScraperAPIClient('YOUR_API_KEY');
Ruby
Ruby projects use Bundler or RubyGems for dependency management. The scraperapi-ruby gem is available:
gem install scraperapi-ruby
To integrate into your Ruby code:
require 'scraperapi'
client = ScraperAPI::Client.new(api_key: 'YOUR_API_KEY')
PHP
PHP projects typically use Composer to manage dependencies. The ScraperApi PHP library can be added to your composer.json:
composer require scraperapi/scraperapi-php
Example usage in PHP:
<?php
require 'vendor/autoload.php';
use ScraperAPI\ScraperAPIClient;
$client = new ScraperAPIClient('YOUR_API_KEY');
?>
Java and Go
For Java and Go, while dedicated SDKs are not provided, ScraperApi documentation offers specific examples for making direct HTTP requests. Developers typically integrate an HTTP client library (e.g., OkHttp or Apache HttpClient for Java, or the standard net/http package for Go) and construct URLs with the ScraperAPI endpoint and parameters ScraperApi Go integration. The API key is appended as a query parameter.
Quickstart example
The following quickstart examples demonstrate how to make a basic request to ScraperApi using the official SDKs in Python and Node.js. These examples illustrate fetching content from a target URL, with the ScraperApi handling the proxy rotation and retries.
Python Quickstart
This Python example uses the scraperapi-python SDK to fetch the HTML content of a specified URL. The ScraperAPIClient handles the construction of the API request URL, including your API key and the target URL.
from scraperapi import ScraperAPIClient
# Replace with your actual API key from ScraperApi dashboard
API_KEY = 'YOUR_API_KEY'
TARGET_URL = 'http://httpbin.org/ip'
client = ScraperAPIClient(API_KEY)
try:
# Make a GET request through ScraperApi
response = client.get(TARGET_URL, country_code='us')
# Check if the request was successful
if response.status_code == 200:
print("Successfully fetched content:")
print(response.text)
else:
print(f"Error fetching content: {response.status_code} - {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
This code snippet initializes the client with your unique API key and then calls the .get() method, passing the target URL and optional parameters like country_code to specify the proxy origin. The response object behaves similarly to standard HTTP response objects, allowing access to the status code and text content.
Node.js Quickstart
This Node.js example utilizes the scraperapi npm package to perform a similar web request. It demonstrates how to initialize the client and make an asynchronous request to retrieve web page content.
const ScraperAPIClient = require('scraperapi')();
// Replace with your actual API key from ScraperApi dashboard
const API_KEY = 'YOUR_API_KEY';
const TARGET_URL = 'http://httpbin.org/ip';
const client = new ScraperAPIClient(API_KEY);
async function scrapePage() {
try {
// Make a GET request through ScraperApi
const response = await client.get(TARGET_URL, { country_code: 'us' });
// The response body is typically available directly
console.log("Successfully fetched content:");
console.log(response);
} catch (error) {
console.error(`Error fetching content: ${error.message}`);
}
}
scrapePage();
In this Node.js example, an asynchronous function scrapePage is used to demonstrate fetching content. The client.get() method returns a Promise, allowing for modern asynchronous handling with await. The response directly contains the fetched content, making it straightforward to process.
Community libraries
While official SDKs are provided and supported by ScraperApi, the developer community also contributes libraries and tools that can interact with the API. These community-led initiatives often emerge to address specific use cases, integrate with particular frameworks, or provide alternative implementations in languages not officially supported with a dedicated SDK.
Community libraries for ScraperApi do not have a centralized registry, but they can often be found on platforms like GitHub or package managers (e.g., PyPI for Python, npm for Node.js) by searching for keywords like "scraperapi client" or "scraperapi wrapper." These libraries might offer features such as:
- Integrations with popular scraping frameworks (e.g., Scrapy for Python).
- More opinionated interfaces or higher-level abstractions for common scraping patterns.
- Support for less common programming languages or environments.
When considering a community library, it is advisable to evaluate its maintenance status, community activity, and documentation. Checking the project's repository for recent commits, open issues, and pull requests can provide insight into its ongoing support. For example, a search on GitHub for 'ScraperApi client' or 'ScraperApi wrapper' may reveal various community projects and examples. The official ScraperApi documentation often links to community resources or suggests ways to contribute ScraperApi Community Resources, though direct contribution to their main SDKs is usually through their official channels.
While community libraries can offer valuable extensions or alternative approaches, direct support for these libraries typically falls outside the scope of ScraperApi's official customer service. Users of community-maintained projects will generally rely on the community itself for troubleshooting and updates.