在本地 Windows 中配置 PuppeteerexecutablePath chrome

Nel*_*das 14 node.js puppeteer

  • 傀儡师版本:1.11.0
  • 平台/操作系统版本:Windows 10 pro
  • Node.js 版本:12.6.6

当我在windows中进行本地开发测试时,发生了executablePath的问题。

“无法启动 chrome!spawn /usr/bin/chromium-browser ENOENT”

我看到 Windows 需要获取完整路径。否则找不到chrome.exe

代码中的默认值:

const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});
Run Code Online (Sandbox Code Playgroud)

在 Windows 中它的工作方式如下:

const browser = await puppeteer.launch({executablePath: 'C:\\your_workspace\\node_modules\\puppeteer\\.local-chromium\\win64-(version)\\chrome-win\\chrome.exe'});
Run Code Online (Sandbox Code Playgroud)

在可视化代码中建议路径

可视化代码视图浏览器

che*_*box 12

您还可以设置环境变量PUPPETEER_EXECUTABLE_PATH

PUPPETEER_SKIP_CHROMIUM_DOWNLOAD这与set to结合使用很有用true


小智 11

也许这可以帮助:

const osPlatform = os.platform(); // possible values are: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'
console.log('Scraper running on platform: ', osPlatform);
let executablePath;
if (/^win/i.test(osPlatform)) {
  executablePath = '';
} else if (/^linux/i.test(osPlatform)) {
  executablePath = '/usr/bin/google-chrome';
}
Run Code Online (Sandbox Code Playgroud)