yihong0618 / klingCreator

About High quality video and image generation by https://klingai.kuaishou.com and https://klingai.com/ Reverse engineered API.
GNU General Public License v3.0
113 stars 25 forks source link

Cookie extractor ? #8

Closed raymerjacque closed 3 months ago

raymerjacque commented 3 months ago

is it not possible to code a script to auto login and extract the cookie value ?

something along the lines of :

import time
import cv2
import numpy as np
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

def get_slider_position(captcha_image_path):
    """
    Analyze the CAPTCHA image to find the slider position.
    This function uses image processing to determine the correct position.
    """
    # Load the CAPTCHA image
    captcha_image = cv2.imread(captcha_image_path, 0)

    # Find edges using Canny
    edges = cv2.Canny(captcha_image, 100, 200)

    # Find contours
    contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

    # Sort by area (assuming the largest contour is the slider gap)
    contours = sorted(contours, key=cv2.contourArea, reverse=True)

    for contour in contours:
        x, y, w, h = cv2.boundingRect(contour)
        if w > 50 and h > 50:  # Assuming the slider is of considerable size
            return x

    return None

def solve_slider_captcha(driver, slider, captcha_image_path):
    """
    Automate the slider CAPTCHA solving process.
    """
    # Get the slider position
    position = get_slider_position(captcha_image_path)
    if position is None:
        raise Exception("Slider position not found")

    # Perform the sliding action
    action = ActionChains(driver)
    action.click_and_hold(slider).perform()
    action.move_by_offset(position, 0).perform()
    action.release().perform()

# Setup Selenium WebDriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)

# Open the target website
driver.get("https://klingai.com")

# Log in (assuming the presence of username and password fields)
username_field = driver.find_element(By.ID, "username")
password_field = driver.find_element(By.ID, "password")
login_button = driver.find_element(By.ID, "login")

username_field.send_keys("your_username")
password_field.send_keys("your_password")
login_button.click()

# Wait for CAPTCHA to load
time.sleep(5)

# Locate CAPTCHA slider and CAPTCHA image
slider = driver.find_element(By.CLASS_NAME, "slider")
captcha_image_path = "/path/to/screenshot.png"  # Path to save CAPTCHA image

# Take a screenshot of the CAPTCHA
driver.save_screenshot(captcha_image_path)

# Solve the CAPTCHA
solve_slider_captcha(driver, slider, captcha_image_path)

# Close the browser
driver.quit()
yihong0618 commented 3 months ago

sorry for this repo answer is no, its a little heavy and can't not run in the server.

but your code looks good, you can fork it and do whatever you want, we can put your repo in README