StealthKit Documentation

repository·main·Indexed 41 days ago

https://github.com/theonlyanil/stealthkit

A 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().

Tokens
827
Snippets
5
Records
5
Agent score
2%

What's inside StealthKit

  1. Basic usage of StealthSession

    main

    To 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")
  2. Manage headers and cookies in StealthSession

    main

    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()
  3. Configure StealthSession with proxies and retries

    main

    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)
  4. Perform RESTful requests with StealthSession

    main

    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")