{
  "openapi": "3.0.3",
  "info": {
    "title": "Web Scraping API",
    "version": "1.0.0",
    "description": "Scrape any URL to raw HTML, clean text, or structured JSON using FlareSolverr for Cloudflare bypass. Two modes: scrape returns the full page content, extract returns only the fields you specify via CSS selectors. Handles JavaScript-rendered pages and bot-protection.\n",
    "contact": {
      "name": "Web Scraping API Support",
      "email": "api@hiroapp.cc"
    }
  },
  "servers": [
    {
      "url": "https://api.sprytools.com/v1/scraping",
      "description": "Production (SpryTools API Gateway)"
    }
  ],
  "tags": [
    {
      "name": "Scrape",
      "description": "Fetch full page content"
    },
    {
      "name": "Extract",
      "description": "Extract structured data via CSS selectors"
    }
  ],
  "security": [
    {
      "ApiKeyHeader": []
    },
    {
      "RapidApiProxy": []
    }
  ],
  "paths": {
    "/api/v1/scrape": {
      "post": {
        "operationId": "scrapeUrl",
        "summary": "Scrape a URL to HTML or text",
        "description": "Fetch a web page (with Cloudflare bypass via FlareSolverr) and return the raw HTML, clean extracted text, or both. Use `output=html` for raw HTML only, `output=text` for cleaned text only, or omit for both.\n",
        "tags": [
          "Scrape"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScrapeRequest"
              },
              "example": {
                "url": "https://example.com",
                "output": "json",
                "maxTimeout": 30000
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scraped page content",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScrapeResult"
                },
                "example": {
                  "url": "https://example.com",
                  "html": "<html>...</html>",
                  "text": "Example Domain This domain is for use in illustrative examples.",
                  "statusCode": 200
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/FlareSolverrError"
          }
        }
      }
    },
    "/api/v1/extract": {
      "post": {
        "operationId": "extractSelectors",
        "summary": "Extract structured data via CSS selectors",
        "description": "Scrape a URL and extract specific fields using CSS selectors. Provide a `selectors` object mapping field names to CSS selector strings. Returns a data object with one key per selector.\n",
        "tags": [
          "Extract"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtractRequest"
              },
              "example": {
                "url": "https://example.com",
                "selectors": {
                  "title": "h1",
                  "description": "p"
                },
                "maxTimeout": 30000
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extracted data",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExtractResult"
                },
                "example": {
                  "url": "https://example.com",
                  "data": {
                    "title": "Example Domain",
                    "description": "This domain is for use in illustrative examples."
                  },
                  "statusCode": 200
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/FlareSolverrError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      },
      "RapidApiProxy": {
        "type": "apiKey",
        "in": "header",
        "name": "x-rapidapi-proxy-secret"
      }
    },
    "schemas": {
      "ScrapeRequest": {
        "type": "object",
        "required": [
          "url"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL to scrape (http or https only)"
          },
          "output": {
            "type": "string",
            "enum": [
              "json",
              "html",
              "text"
            ],
            "default": "json",
            "description": "Output mode — json returns both html and text fields, html returns only raw HTML, text returns only cleaned text\n"
          },
          "maxTimeout": {
            "type": "integer",
            "description": "Maximum wait time in milliseconds (default 30000)",
            "default": 30000,
            "minimum": 1000,
            "maximum": 120000
          }
        }
      },
      "ScrapeResult": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "html": {
            "type": "string",
            "nullable": true
          },
          "text": {
            "type": "string",
            "nullable": true
          },
          "statusCode": {
            "type": "integer"
          }
        }
      },
      "ExtractRequest": {
        "type": "object",
        "required": [
          "url",
          "selectors"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "URL to scrape"
          },
          "selectors": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Mapping of field names to CSS selector strings"
          },
          "maxTimeout": {
            "type": "integer",
            "description": "Maximum wait time in milliseconds",
            "default": 30000,
            "minimum": 1000,
            "maximum": 120000
          }
        }
      },
      "ExtractResult": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "data": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "nullable": true
            }
          },
          "statusCode": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad request — missing or invalid parameters",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "url is required"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "API key missing",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "API key required"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded (100 requests per minute)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Rate limit exceeded"
            }
          }
        }
      },
      "InternalError": {
        "description": "Internal scraping error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "Scraping failed"
            }
          }
        }
      },
      "FlareSolverrError": {
        "description": "FlareSolverr upstream error (Cloudflare bypass service unavailable)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "FlareSolverr request failed: connection refused"
            }
          }
        }
      }
    }
  }
}