[Python] Selenium deletes chrome profiles

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    Selenium deletes chrome profiles. It happens ~1 in 30 times

    My code:

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager
    import os, sys, time, json, glob
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as ec
    import shutil,requests
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument(r'user-data-dir=C:\Users\Danzel\AppData\Local\Google\Chrome\User Data')
    chrome_options.add_argument(r'profile-directory=Profile 9')
    chrome_options.add_argument("--remote-debugging-port=9222") # this
    chrome_options.add_argument('--disable-blink-features=AutomationControlled')
    chrome_options.add_argument('--disable-web-security')
    chrome_options.add_argument('--disable-setuid-sandbox')
    chrome_options.add_argument('--allow-running-insecure-content')
    try:
    driver = webdriver.Chrome(ChromeDriverManager().install(),chrome_options=chrome_options)
    except ValueError:
    driver = webdriver.Chrome(ChromeDriverManager(version="116.0.5845.96").install(),chrome_options=chrome_options)
    #driver = webdriver.Chrome(chromedriver_autoinstaller.install(), options=chrome_options)
    driver.implicitly_wait(1)

    driver.get("https://www.google.com/")

    #some code

    driver.close()
    try:
    [x.kill() for x in psutil.process_iter() if 'chrome' in x.name().lower()]
    except psutil.NoSuchProcess:
    pass


    And i get empty browser: [​IMG]

    However, the profiles are still located in the \AppData\Local\Google\Chrome\User Data folder: [​IMG]

    why they were removed from the browser?

    Continue reading...

Compartilhe esta Página