【问题标题】:Create Chrome profiles without launching Chrome?在不启动 Chrome 的情况下创建 Chrome 配置文件?
【发布时间】:2017-09-02 10:09:17
【问题描述】:

这可用于自动创建新的 Chrome 配置文件。我正在使用 Windows,除了它启动 Chrome 之外,这往往会起作用。

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --profile-directory="Profile 1"

我只是想知道是否有办法做到这一点,以便我可以更快地创建配置文件,因为它使用大量 CPU。 Firefox 创建配置文件而不启动它们。

这些配置文件稍后将在 Selenium 中使用

谢谢

【问题讨论】:

    标签: google-chrome selenium command-line command


    【解决方案1】:

    您应该使用 NodeJS 和 chrome headless 来自动执行此操作。请看下面的网址

    https://developers.google.com/web/updates/2017/04/headless-chrome

    const chromeLauncher = require('chrome-launcher');
    
    function createChromeProfile(profileName) {
      return chromeLauncher.launch({
        // port: 9222, // Uncomment to force a specific port of your choice.
        chromeFlags: [
          '--profile-directory="' + profileName + '"',
          '--window-size=412,732',
          '--disable-gpu',
          '--headless'
        ]
      });
    }
    
    createChromeProfile("Profile 1").then(chrome => {
      console.log(`Chrome debuggable on port: ${chrome.port}`);
      ...
      chrome.kill();
    });
    

    【讨论】:

    • 我在 Python 3 中得到了很多未解决的引用。如果我想为 Firefox 和 Chrome 创建 100 个配置文件,这将很难做到。
    • 我从未使用过 NodeJ。我在 Pycharm 中使用 python。嗯... Pycharm 通过扩展支持 NodeJs...
    • 使用 NodeJS 会更容易,因为代码很容易获得
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    相关资源
    最近更新 更多