SDKs overview

ScrapingAnt offers an HTTP-based API for web scraping, which can be accessed directly via cURL or integrated using language-specific SDKs and client libraries. These libraries abstract away the complexities of HTTP requests, parameter formatting, and response parsing, enabling developers to focus on data extraction logic rather than infrastructure management. The API itself manages aspects such as JavaScript rendering and proxy rotation, which are critical for scraping dynamic websites and bypassing anti-bot measures.

The core functionality supported by the SDKs includes sending requests to target URLs, configuring browser options, setting proxy types, and handling various response formats. Developers can specify parameters such as url, browser (to enable headless Chrome), proxy_type (for residential or datacenter proxies), and custom headers. The API returns the HTML content of the target page, along with status information.

While official SDKs are provided for common languages, the API's RESTful nature means it can be consumed by any programming language capable of making HTTP requests. This flexibility allows developers to choose their preferred environment, whether it's Python for data science, Node.js for backend services, or PHP for web development. The documentation provides clear examples across these languages to facilitate integration.

It is important to note that many web scraping tasks involve handling HTTP status codes, managing retries, and parsing HTML or JSON responses. While SDKs simplify the initial request, developers are still responsible for implementing robust error handling and data parsing strategies within their applications. Tools like Beautiful Soup for Python or Cheerio for Node.js are often used in conjunction with scraping APIs to extract specific data points from the returned HTML.

Official SDKs by language

ScrapingAnt provides official client libraries for several popular programming languages. These SDKs are designed to streamline the integration process, offering idiomatic interfaces for common API operations. The table below outlines the officially supported SDKs, their respective package managers, and typical installation commands.

Language Package Name Installation Command Maturity
Python scrapingant-client pip install scrapingant-client Stable
Node.js scrapingant-client npm install scrapingant-client Stable
PHP scrapingant/scrapingant-client composer require scrapingant/scrapingant-client Stable
Ruby scrapingant gem install scrapingant Stable
Go github.com/scrapingant/scrapingant-go go get github.com/scrapingant/scrapingant-go Stable
Java (Maven/Gradle dependency) (Example provided in ScrapingAnt Java documentation) Stable

Each SDK is maintained to reflect the current API capabilities and ensure compatibility. Developers are encouraged to refer to the official ScrapingAnt documentation for the most up-to-date installation instructions and usage examples specific to each language.

Installation

Installation of ScrapingAnt SDKs typically follows the standard package management practices for each programming language. Below are detailed instructions for popular languages.

Python Installation

The Python SDK can be installed using pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.

python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
pip install scrapingant-client

Node.js Installation

For Node.js projects, the SDK is available via npm, the Node.js package manager.

npm install scrapingant-client

Alternatively, if you prefer Yarn:

yarn add scrapingant-client

PHP Installation

PHP projects typically use Composer for dependency management.

composer require scrapingant/scrapingant-client

Ruby Installation

Ruby gems are managed through Bundler or directly with the gem command.

gem install scrapingant

If you are using Bundler, add this to your Gemfile:

gem 'scrapingant'

Then run bundle install.

Go Installation

Go modules are used for dependency management in Go projects.

go get github.com/scrapingant/scrapingant-go

Java Installation

For Java, you would typically add a dependency to your Maven pom.xml or Gradle build.gradle file. Specific dependency coordinates are provided in the ScrapingAnt Java guide.

Quickstart example

This section provides a quickstart example using the Python SDK to demonstrate how to fetch HTML content from a URL. Replace YOUR_API_KEY with your actual ScrapingAnt API key.

Python Quickstart

This example demonstrates how to use the scrapingant-client to fetch a webpage, enabling JavaScript rendering.

from scrapingant_client import ScrapingAntClient, ScrapeOptions
import os

# Replace with your actual API key, or get it from environment variables
API_KEY = os.environ.get("SCRAPINGANT_API_KEY", "YOUR_API_KEY")

client = ScrapingAntClient(token=API_KEY)

try:
    # Scrape a URL with JavaScript rendering enabled
    response = client.scrape(
        url="https://www.example.com",
        scrape_options=ScrapeOptions(browser=True) # Enable headless Chrome
    )

    print(f"Status Code: {response.status_code}")
    print("------ HTML Content ------")
    print(response.content[:500]) # Print first 500 characters of HTML

except Exception as e:
    print(f"An error occurred: {e}")

Node.js Quickstart

This Node.js example uses the scrapingant-client to fetch a page, including JavaScript rendering.

const { ScrapingAntClient } = require('scrapingant-client');

// Replace with your actual API key, or get it from environment variables
const API_KEY = process.env.SCRAPINGANT_API_KEY || 'YOUR_API_KEY';

const client = new ScrapingAntClient({ apiKey: API_KEY });

async function scrapePage() {
  try {
    const response = await client.scrape({
      url: 'https://www.example.com',
      browser: true, // Enable headless Chrome
    });

    console.log(`Status Code: ${response.statusCode}`);
    console.log('------ HTML Content ------');
    console.log(response.content.substring(0, 500)); // Print first 500 characters

  } catch (error) {
    console.error(`An error occurred: ${error.message}`);
  }
}

scrapePage();

cURL Example (Direct API Call)

For languages without an official SDK or for quick tests, you can use cURL to make a direct HTTP request to the ScrapingAnt API. This demonstrates the underlying API structure.

curl -X GET "https://api.scrapingant.com/v2/general?url=https://www.example.com&x-api-key=YOUR_API_KEY&browser=true"

This cURL command sends a GET request to the ScrapingAnt API endpoint, specifying the target URL, your API key, and enabling browser rendering. The response will be the HTML content of the target page.

Community libraries

While ScrapingAnt provides official SDKs, the API's standard HTTP methods and JSON/HTML response formats allow for easy integration with generic HTTP client libraries available in virtually any programming language. Developers can choose to build their own client wrappers or use existing, widely adopted HTTP libraries. Examples of such libraries include:

  • Python: requests (Requests library documentation) - a popular and user-friendly HTTP library.
  • Node.js: axios or the built-in node-fetch (Axios library documentation: axios-http.com) - robust choices for making HTTP requests.
  • PHP: Guzzle HTTP Client (Guzzle documentation) - a widely used and feature-rich HTTP client for PHP.
  • Ruby: httparty or the built-in Net::HTTP (HTTParty gem documentation: github.com/jnunemaker/httparty) - options for making HTTP requests in Ruby applications.
  • Go: The standard library's net/http package (Go net/http package) is fully capable of interacting with the ScrapingAnt API.
  • Java: Apache HttpClient or OkHttp - common choices for robust HTTP communication in Java.

These generic HTTP clients provide low-level control over requests, headers, and error handling, giving developers maximum flexibility. However, they require manual construction of API URLs and parsing of responses, which the official SDKs aim to simplify.

For more complex scraping scenarios or integrating with other data processing pipelines, developers might also leverage broader web scraping frameworks that can incorporate ScrapingAnt as a proxy or rendering service. For example, a Python developer might use Scrapy to manage the overall crawling logic and delegate the actual page fetching to ScrapingAnt via a custom downloader middleware.