美文网首页
Set "PUPPETEER_SKIP_CHROMIUM_DOW

Set "PUPPETEER_SKIP_CHROMIUM_DOW

作者: mayufo | 来源:发表于2019-04-22 15:12 被阅读0次

    问题

    最近学node, 之前用puppeteer写的抓包工具报错

    UnhandledPromiseRejectionWarning: Error: Chromium revision is not downloaded. Run "npm install" or "yarn install"错误

    但是如果你真的yarn一下就会报类似

    Set "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD报错

    解决

    手动下载Chromium

    下载地址:https://download-chromium.appspot.com/

    把下载刚刚下载的文件解压到项目的chromium文件夹下,在chromium文件夹下你会看到chrome-mac文件

    image.png

    创建src/app.js

    (async () => {
        const browser = await puppeteer.launch({
            executablePath: '../chromium/Chromium.app/Contents/MacOS/Chromium',
            headless: false
        });
        const page = await browser.newPage();
        await page.goto('https://www.baidu.com');
    
        // Get the "viewport" of the page, as reported by the page.
        const dimensions = await page.evaluate(() => {
            return {
                width: document.documentElement.clientWidth,
                height: document.documentElement.clientHeight,
                deviceScaleFactor: window.devicePixelRatio
            };
        });
    
        console.log('Dimensions:', dimensions);
    
        await browser.close();
    })();
    

    以上解决!

    相关文章

      网友评论

          本文标题:Set "PUPPETEER_SKIP_CHROMIUM_DOW

          本文链接:https://www.haomeiwen.com/subject/bebygqtx.html