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();
    }
相关推荐
天波信息技术分享几秒前
AI云电脑盒子技术分析——从“盒子”到“算力云边缘节点”的跃迁
人工智能·电脑
CoderJia程序员甲14 分钟前
GitHub 热榜项目 - 日榜(2025-08-16)
人工智能·ai·开源·github
KirkLin15 分钟前
Kirk:练习时长两年半的AI Coding经验
人工智能·程序员·全栈
mit6.82420 分钟前
[1Prompt1Story] 注意力机制增强 IPCA | 去噪神经网络 UNet | U型架构分步去噪
人工智能·深度学习·神经网络
挽淚37 分钟前
(小白向)什么是Prompt,RAG,Agent,Function Calling和MCP ?
人工智能·程序员
Jina AI44 分钟前
回归C++: 在GGUF上构建高效的向量模型
人工智能·算法·机器学习·数据挖掘·回归
科大饭桶1 小时前
昇腾AI自学Day2-- 深度学习基础工具与数学
人工智能·pytorch·python·深度学习·numpy
什么都想学的阿超2 小时前
【大语言模型 02】多头注意力深度剖析:为什么需要多个头
人工智能·语言模型·自然语言处理
努力还债的学术吗喽2 小时前
2021 IEEE【论文精读】用GAN让音频隐写术骗过AI检测器 - 对抗深度学习的音频信息隐藏
人工智能·深度学习·生成对抗网络·密码学·音频·gan·隐写
明道云创始人任向晖2 小时前
20个进入实用阶段的AI应用场景(零售电商业篇)
人工智能·零售