Edge浏览器设置网页自动翻译

一.浏览网页自动翻译

设置->扩展->获取Microsoft Edge扩展->搜索"沉浸式翻译"->获取 。

提示:如果采用其他的翻译扩展没找自动翻译功能,所以这里选择"沉浸式翻译"

二.基于Java WebElement时自动翻译

Java关键代码:

提示:在运行代码前注意结束进程!否则会报错! Could not start a new session. Response code 500. Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

java 复制代码
private static WebDriver driver = null;
    public static void main(String[] args) {
        String url = "https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH";
        try {
           initEdge("2");
           getDriver().get(url);
           Thread.sleep(100000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }

    }
public static void initEdge(String type) {
        System.setProperty("webdriver.edge.driver", "D:/edgedriver-win64/msedgedriver.exe");
        EdgeOptions options = new EdgeOptions();
        options.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
        //  指定用户数据目录(复用本地浏览器的缓存、Cookie、扩展等)
        options.addArguments("--user-data-dir=C:\\Users\\Admin\\AppData\\Local\\Microsoft\\Edge\\User Data");

        // 1.基本反检测配置
        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
        options.setExperimentalOption("useAutomationExtension", false);

        // 2. 禁用自动化控制标志
        options.addArguments("--disable-blink-features=AutomationControlled");

        // 3. 禁用 Infobars(可能暴露自动化)
        options.addArguments("--disable-infobars");

        // 4. 禁用扩展和插件
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("--no-sandbox");

        // 5. 禁用 GPU 加速(某些网站会检测)
        options.addArguments("--disable-gpu");

        // 6. 设置合法的 User-Agent(带 Edge 标识)
        options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0");

        // 7. 无头模式(可选)
        if ("1".equals(type)) {
            options.addArguments("--headless=new"); // Edge 115+ 使用 headless=new
        }

        // 8. 禁用 WebDriver 特征(关键!)
        options.addArguments("--disable-web-security");
        options.addArguments("--allow-running-insecure-content");

        // 9. 禁用通知弹窗
        options.addArguments("--disable-notifications");

        // 10. 禁用密码保存提示
        options.addArguments("--disable-save-password-prompt");

        // 11. 禁用同源策略(可选,可能影响登录)
        // options.addArguments("--disable-site-isolation-trials");
        // 设置代理(例如:123.123.123.123:8080)
        Proxy proxy = new Proxy();
        proxy.setHttpProxy("123.123.123.123:8080");
        options.setCapability("proxy", proxy);
        driver = new EdgeDriver(options);

        // 12. 进一步隐藏 WebDriver 特征(通过 JavaScript)
        ((JavascriptExecutor) driver).executeScript(
                "Object.defineProperty(navigator, 'webdriver', {get: () => false});" +
                        "window.outerWidth = window.innerWidth;" +
                        "window.outerHeight = window.innerHeight;"
        );
    }

    public static WebDriver getDriver() {
        return driver;
    }

    /**
     * 关闭工具进程
     */
    public static void quit() {
        driver.quit();
    }
相关推荐
LucianaiB4 小时前
“AI+OPC”创新应用专业赛
人工智能
北龙云海4 小时前
AI驱动数据库运维变革:北龙云海智能巡检平台实践与展望
运维·数据库·人工智能
GlobalInfo4 小时前
2026年全球无人机清洗系统市场深度分析:规模、竞争格局与AI自主作业演进趋势
大数据·人工智能·ai·无人机
中杯可乐多加冰4 小时前
从 SDK 到桌面应用:我用科沃斯八界把视觉、导航和机械臂接起来
人工智能·机器人·sdk·具身智能·科沃斯·八界创造者计划·科沃斯八界
创世虚拟世界4 小时前
我做了一个 3D 虚拟世界基底,基于这个再做 3D 虚拟世界或者元宇宙,会事半功倍
javascript·人工智能·3d·gitee·虚拟现实
AI职业加油站4 小时前
AI 校招现状:大模型应用工程师证书,助力简历能力证明
大数据·运维·人工智能·学习·职场发展
知几蜗牛4 小时前
GPT-6 与 Intelligent UI:从回答到可审计操作的产品迁移
人工智能
蟕初的梦想4 小时前
Claude Haiku 5.5 效能实测与场景应用指南
数据库·人工智能·大模型
liron714 小时前
技术的诞生与演化--技术自举及其冷启动
人工智能·深度学习·神经网络·自然语言处理
知几蜗牛4 小时前
Java 17 视觉识别结果的金额与字段门禁实现
人工智能