Skip to main content

A powerful web scraping and API reversal tool

Project description

WebChameleon

Python License Version

WebChameleon is a powerful tool for web scraping and API reversal, designed for developers, data researchers, and tech professionals. With features like dynamic structure analysis, automatic API detection, and graph-based relation mapping, WebChameleon enables efficient and ethical data extraction from various websites.

Key Features

  • Dynamic Structure Analysis: Automatically understands website layouts with semantic analysis using NLTK.
  • Automatic API Detection: Discovers hidden API endpoints using Playwright simulation and heuristic approaches.
  • Graph-Based Relation Mapping: Builds relationship graphs between entities with community analysis using the Louvain method.
  • Adaptive Error Handling: Automatic retry mechanisms, adaptive rate limiting, and recovery strategies when blocked.
  • Flexible Storage: Saves data in JSON, CSV, or SQLite formats with compression options.
  • Disguise and Authentication: Supports multiple disguise modes (browser, bot, API client) and authentication via headers/cookies.

Prerequisites

  • Python 3.7+: Ensure Python is installed. Download it here.
  • pip: Installed by default with Python.
  • Git: Optional, used for cloning the repository.

Installation Steps

  1. Clone the Repository
git clone https://github.com/mrivky67/webchameleon.git
cd webchameleon
  1. Create a Virtual Environment (Recommended)
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Unix/macOS:
source venv/bin/activate
  1. Install Dependencies
pip install -r requirements.txt
  1. Install Playwright Browsers
playwright install
  1. Download NLTK Data
import nltk
nltk.download('punkt')
  1. Verify Installation
python examples/reverse_api_example.py

Troubleshooting

  • Error: "Can not decode content-encoding: brotli"
    pip install brotli
    
  • Error: "Playwright browser not found" Ensure you've run playwright install.
  • Error: "NLTK data not found" Run nltk.download('punkt') again.

Installing as a Package

pip install -e .

You can now import WebChameleon from anywhere:

from webchameleon import WebChameleon

Usage Guide

This guide provides examples for website scraping and API reverse-engineering.

Scraping a Website

  1. Define the Target Choose a website, e.g., https://scrapethissite.com/pages/simple/.

  2. Inspect HTML Structure Use Chrome DevTools. Example classes:

  • .country-name
  • .country-capital
  • .country-population
  1. Write the Script
import asyncio
from webchameleon import WebChameleon

async def main():
    chameleon = WebChameleon(
        target="https://scrapethissite.com/pages/simple/",
        disguise_as="default",
        auto_learn=True,
        max_concurrent=5
    )

    structure = await chameleon.analyze_structure()
    print("Structure:", structure)

    data = await chameleon.scrape(
        target_elements={
            "country_name": ".country-name",
            "capital": ".country-capital",
            "population": ".country-population"
        },
        depth=3,
        adaptive_depth=True
    )
    await chameleon.save(data, "countries_data.json", format="json", compress=True)

if __name__ == "__main__":
    asyncio.run(main())
  1. Run the Script
python examples/scrape_forum.py

Detecting APIs (Reverse API)

  1. Target a Site with APIs Example: https://reqres.in

  2. Write the Script

import asyncio
from webchameleon import WebChameleon

async def main():
    chameleon = WebChameleon(
        target="https://reqres.in",
        disguise_as="python_requests"
    )

    api_data = await chameleon.reverse_api(use_playwright=True, max_depth=4, interactive_mode=True)
    if api_data:
        await chameleon.save(api_data, "reqres_api_data.json", format="json", compress=True)
        print("API Data:", api_data)
    else:
        print("No API detected.")

if __name__ == "__main__":
    asyncio.run(main())
  1. Run the Script
python examples/reverse_api_example.py

Mapping Relations

relations = await chameleon.map_relations(data, "relations.graphml", weight_threshold=0.6)

Key Parameters

  • disguise_as: e.g., default, googlebot, python_requests
  • max_concurrent: Controls concurrency.
  • auth_config: Pass authentication headers.
auth_config={"headers": {"Authorization": "Bearer your_api_key"}}
  • use_playwright: Set to True for dynamic sites.

API Reference

WebChameleon Class

chameleon = WebChameleon(
    target: str,
    disguise_as: str = "default",
    auto_learn: bool = True,
    max_concurrent: int = 5,
    auth_config: Optional[Dict] = None,
    custom_settings: Optional[Dict] = None
)

Methods

  • analyze_structure()Optional[Dict]
  • scrape(target_elements: Dict, depth: int, adaptive_depth: bool)List[Dict]
  • reverse_api(use_playwright: bool, max_depth: int, interactive_mode: bool)Optional[Dict]
  • map_relations(data: List[Dict], output_file: str, weight_threshold: float)Optional[Dict]
  • save(data: List[Dict], filename: str, format: str, compress: bool)
  • status()Dict

Supporting Classes

  • StructureAnalyzer
  • ApiReverser
  • RelationMapper
  • DisguiseManager
  • StorageManager

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webchameleon_tool-1.3.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webchameleon_tool-1.3.0-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file webchameleon_tool-1.3.0.tar.gz.

File metadata

  • Download URL: webchameleon_tool-1.3.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for webchameleon_tool-1.3.0.tar.gz
Algorithm Hash digest
SHA256 78e7e279194048c46ff154917d1f4ad4e534bdd6b9b7dd573281d0448d2b6064
MD5 e75a9a4724145c57d42ff20b2ca9a846
BLAKE2b-256 5540a00ec146e28aefa6cf2a91b224029055f66357882bc284782214cae51463

See more details on using hashes here.

File details

Details for the file webchameleon_tool-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for webchameleon_tool-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fce0dff83a9920883ab1a373f0fe75e333fdf9e22d4950d63c7a974903be538
MD5 6d7d7e92617a1a9b56fb345f45fab1b7
BLAKE2b-256 69ecccdd614427ed430160990f28ec92ae0de73f3308ed59ffd2b37298a1600c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page