selenium 实现自动登录功能【Use 缓存】

    options = webdriver.ChromeOptions()
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument("--disable-blink-features=AutomationControlled")
    options.add_argument(
        'user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"')
    user_cache_folder = f"{get_doc_path()}\\project_name\user_data"
    disk_cache_folder = f"{get_doc_path()}\\project_name\\disk_data"
    mkdir_doc_data(user_cache_folder)
    mkdir_doc_data(disk_cache_folder)
    options.add_argument(f"--user-data-dir={user_cache_folder}") # 设置缓存用户文件目录
    options.add_argument(f"--disk-cache-dir={disk_cache_folder}") # 设置缓存硬盘文件目录

重点在于
options.add_argument(f"–user-data-dir={user_cache_folder}“) # 设置缓存用户文件目录
options.add_argument(f”–disk-cache-dir={disk_cache_folder}") # 设置缓存硬盘文件目录

你可能感兴趣的:(Python,selenium,缓存,测试工具)