### Unflare API Error Response Example (JSON) Source: https://github.com/iamyegor/unflare/blob/main/README.md This JSON structure illustrates an error response from the Unflare API. It includes an error code and a descriptive message explaining the issue encountered during the scraping process. ```json { "code": "error", "message": "..." } ``` -------------------------------- ### Unflare API Request Example (JSON) Source: https://github.com/iamyegor/unflare/blob/main/README.md This JSON structure defines the payload for an API request to the Unflare service. It includes the target URL, a timeout value, the HTTP method (GET or POST), optional form data for POST requests, and proxy configuration details. ```json { "url": "https://example.com", "timeout": 60000, "method": "GET", "proxy": { "host": "proxy.example.com", "port": 8080, "username": "user", "password": "pass" } } ``` -------------------------------- ### Unflare Usage with Curl (POST Request) Source: https://github.com/iamyegor/unflare/blob/main/README.md This command demonstrates how to interact with the Unflare API using `curl` for a GET request. It sends a POST request to the `/scrape` endpoint with a JSON payload specifying the target URL and timeout. ```bash curl -X POST http://localhost:5002/scrape \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com", "timeout": 60000}' ``` -------------------------------- ### Unflare API Successful Response Example (JSON) Source: https://github.com/iamyegor/unflare/blob/main/README.md This JSON structure represents a successful response from the Unflare API. It contains an array of cookies, including the critical `cf_clearance` token, and an object of headers that can be used for subsequent requests to the target website. ```json { "cookies": [ { "name": "cf_clearance", "value": "abc123...", "domain": ".example.com", "path": "/", "expires": 1676142392.307484, "httpOnly": true, "secure": true } ], "headers": { "user-agent": "Mozilla/5.0..." } } ``` -------------------------------- ### Unflare Deployment with Docker (Build and Run) Source: https://github.com/iamyegor/unflare/blob/main/README.md These Docker commands illustrate how to build the Unflare image from the Dockerfile and then run it as a container, exposing the service on port 5002. ```bash docker build -t unflare . docker run -p 5002:5002 unflare ``` -------------------------------- ### Unflare Deployment with Docker Compose Source: https://github.com/iamyegor/unflare/blob/main/README.md This YAML configuration defines how to deploy the Unflare service using Docker Compose. It specifies the image to use and maps the container's port 5002 to the host's port 5002. ```yaml services: unflare: image: ghcr.io/iamyegor/unflare ports: - "5002:5002" ``` -------------------------------- ### POST /scrape Source: https://github.com/iamyegor/unflare/blob/main/README.md Scrape a target URL protected by Cloudflare. This endpoint handles Cloudflare challenges and returns valid session cookies (e.g., cf_clearance) and browser headers. ```APIDOC ## POST /scrape ### Description This endpoint bypasses Cloudflare protection for a given URL. It uses Puppeteer to solve challenges and returns the necessary cookies and headers to access the target website directly. ### Method POST ### Endpoint /scrape #### Request Body - **url** (string) - Required - The target URL to scrape. - **timeout** (number) - Required - The maximum time in milliseconds to wait for the Cloudflare challenge to be solved. - **method** (string) - Optional - The HTTP method to use for the request. Defaults to "GET". Can be "GET" or "POST". - **data** (object) - Optional - Form data to be sent with POST requests. - **proxy** (object) - Optional - Proxy configuration details. - **host** (string) - Required if proxy is used - The proxy server host. - **port** (number) - Required if proxy is used - The proxy server port. - **username** (string) - Optional - The username for proxy authentication. - **password** (string) - Optional - The password for proxy authentication. ### Request Example ```json { "url": "https://example.com", "timeout": 60000, "method": "GET", "proxy": { "host": "proxy.example.com", "port": 8080, "username": "user", "password": "pass" } } ``` ### Response #### Success Response (200) - **cookies** (array) - An array of cookie objects, including the `cf_clearance` token. - **name** (string) - The name of the cookie (e.g., `cf_clearance`). - **value** (string) - The value of the cookie. - **domain** (string) - The domain for which the cookie is valid. - **path** (string) - The path for which the cookie is valid. - **expires** (number) - The expiration date of the cookie. - **httpOnly** (boolean) - Indicates if the cookie is httpOnly. - **secure** (boolean) - Indicates if the cookie is secure. - **headers** (object) - An object containing browser headers. - **user-agent** (string) - The User-Agent header. #### Response Example ```json { "cookies": [ { "name": "cf_clearance", "value": "abc123...", "domain": ".example.com", "path": "/", "expires": 1676142392.307484, "httpOnly": true, "secure": true } ], "headers": { "user-agent": "Mozilla/5.0..." } } ``` #### Error Response ```json { "code": "error", "message": "..." } ``` ``` -------------------------------- ### Unflare Usage with JavaScript Fetch API Source: https://github.com/iamyegor/unflare/blob/main/README.md This JavaScript code snippet shows how to use the `fetch` API to send a POST request to the Unflare `/scrape` endpoint. It includes the necessary headers and a JSON body containing the URL, timeout, and proxy configuration. The response is then parsed to extract cookies and headers for subsequent requests. ```javascript const res = await fetch('http://localhost:5002/scrape', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: 'https://example.com', timeout: 60000, proxy: { host: "proxy.example.com", port: 8080, username: "user", password: "pass" } }) }); const { cookies, headers } = await res.json(); // Use cookies/headers for next requests ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.