A powerful web scraping and API reversal tool
Project description
WebChameleon
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
- Clone the Repository
git clone https://github.com/mrivky67/webchameleon.git
cd webchameleon
- Create a Virtual Environment (Recommended)
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Unix/macOS:
source venv/bin/activate
- Install Dependencies
pip install -r requirements.txt
- Install Playwright Browsers
playwright install
- Download NLTK Data
import nltk
nltk.download('punkt')
- 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
-
Define the Target Choose a website, e.g.,
https://scrapethissite.com/pages/simple/. -
Inspect HTML Structure Use Chrome DevTools. Example classes:
.country-name.country-capital.country-population
- 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())
- Run the Script
python examples/scrape_forum.py
Detecting APIs (Reverse API)
-
Target a Site with APIs Example:
https://reqres.in -
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())
- 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_requestsmax_concurrent: Controls concurrency.auth_config: Pass authentication headers.
auth_config={"headers": {"Authorization": "Bearer your_api_key"}}
use_playwright: Set toTruefor 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
StructureAnalyzerApiReverserRelationMapperDisguiseManagerStorageManager
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e7e279194048c46ff154917d1f4ad4e534bdd6b9b7dd573281d0448d2b6064
|
|
| MD5 |
e75a9a4724145c57d42ff20b2ca9a846
|
|
| BLAKE2b-256 |
5540a00ec146e28aefa6cf2a91b224029055f66357882bc284782214cae51463
|
File details
Details for the file webchameleon_tool-1.3.0-py3-none-any.whl.
File metadata
- Download URL: webchameleon_tool-1.3.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fce0dff83a9920883ab1a373f0fe75e333fdf9e22d4950d63c7a974903be538
|
|
| MD5 |
6d7d7e92617a1a9b56fb345f45fab1b7
|
|
| BLAKE2b-256 |
69ecccdd614427ed430160990f28ec92ae0de73f3308ed59ffd2b37298a1600c
|