【问题标题】:node.js win10 puppeteer executablePath stringnode.js win10 puppeteer 可执行路径字符串
【发布时间】:2020-09-24 06:56:49
【问题描述】:

我在 Windows 10 命令提示符下使用 node.js 项目,该项目应该使用 puppeteer 启动 chrome,然后执行其他一些网络爬取操作。我已经为这个项目运行了 npm install,但是当我使用 node app.js 运行它时,我收到一个错误“错误:找不到进程“chrome.exe”。 ,我的 puppeteer 代码像这样初始化浏览器:

    let args = ["--lang=en-US,en", '--no-sandbox', '--disable-setuid-sandbox', '--disable-extensions']
    var exPath = "C:\\Users\\marti\\Downloads\\chrome-win\\chrome-win\\chrome.exe"
    var options = {
        executablePath: exPath,
        headless: false,
        args
    };

如果我在另一个命令提示符窗口中运行start C:\\Users\\marti\\Downloads\\chrome-win\\chrome-win\\chrome.exe,它将完美地打开一个铬窗口。 node.js windows 10命令提示符puppeteer是否有我可能缺少的arg?

【问题讨论】:

    标签: javascript node.js npm puppeteer chromium


    【解决方案1】:

    您的请求应该是异步的:

    const browser = await puppeteer.launch({
        executablePath: "C:\\Users\\marti\\Downloads\\chrome-win\\chrome-win\\chrome.exe",
        headless: false,
        args: ["--lang=en-US,en", '--no-sandbox', '--disable-setuid-sandbox', '--disable-extensions']
    });
    

    你使用 puppeteer 的函数应该是 async function 类型

    如果问题仍然存在,请尝试将 '--disable-dev-shm-usage' 参数添加到 args。

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 2018-06-14
      • 2015-07-01
      • 2016-12-01
      • 2016-10-13
      • 1970-01-01
      • 2023-04-06
      • 2011-09-07
      • 1970-01-01
      相关资源
      最近更新 更多