Install StealthKit via pip
mainInstall the stealthkit package using pip to access the StealthSession class for stealthy web scraping and automated requests.
pip install stealthkitrepository·main·Indexed 41 days ago
https://github.com/theonlyanil/stealthkitA Python module for stealthy web scraping and automated requests. It provides the StealthSession class to mimic human browsing behavior through automatic user-agent rotation, randomized referers, and cookie management, supporting standard HTTP methods including .get(), .post(), .put(), and .delete().
Install the stealthkit package using pip to access the StealthSession class for stealthy web scraping and automated requests.
pip install stealthkitTo perform basic web scraping, instantiate StealthSession, fetch cookies from a base URL to establish a session, and then perform requests using methods like .get(). The session automatically handles user-agent rotation and referer randomization.
from stealthkit import StealthSession
# Create a stealth session
sr = StealthSession()
# Fetch cookies from a base URL
sr.fetch_cookies("https://www.example.com")
# Make a GET request
response = sr.get("https://www.example.com/api")
# Print the response JSON if successful
if response:
print(response.json())
else:
print("Failed to fetch data")You can customize the request behavior by setting custom headers via .set_headers(dict) and managing session state using .fetch_cookies(url) to populate the session or .clear_cookies() to reset it.
# Set custom headers
custom_headers = {
"Referer": "https://www.example.com",
"Accept": "application/json",
}
sr.set_headers(custom_headers)
# Clear all stored cookies
sr.clear_cookies()When initializing StealthSession, you can pass a proxies dictionary to route requests through specific proxy servers and a retries integer to define how many times failed requests should be attempted.
# Using Proxies
proxies = {"http": "http://proxy.example.com:8080", "https": "https://proxy.example.com:8080"}
sr = StealthSession(proxies=proxies)
# Configuring Retries
sr = StealthSession(retries=5)The StealthSession object supports standard HTTP methods including .get(), .post(), .put(), and .delete(). For POST and PUT requests, you can pass a json parameter to send a JSON payload.
# GET request
sr.get("https://www.example.com/api")
# POST request with JSON payload
sr.post("https://www.example.com/api", json={"key": "value"})
# PUT request with JSON payload
sr.put("https://www.example.com/api", json={"key": "updated_value"})
# DELETE request
sr.delete("https://www.example.com/api")