Linux_Puppeteer_Chrome 安装笔记

安装chrome浏览器

[visitor@localhost ~]$ vim google-chrome.repo

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

[visitor@localhost ~]$ sudo cp ~/google-chrome.repo /etc/yum.repos.d/

[visitor@localhost ~]$ sudo yum -y install google-chrome-stable –nogpgcheck

[visitor@localhost ~]$ google-chrome -version

Google Chrome 65.0.3325.181

启动浏览器

[visitor@localhost ~]$ google-chrome


安装nodejs和puppeteer

[visitor@localhost ~]$ curl –silent –location https://rpm.nodesource.com/setup_9.x | sudo bash -

[visitor@localhost ~]$ sudo yum -y install nodejs

[visitor@localhost ~]$ node -v

v9.11.1

[visitor@localhost ~]$ npm -v

5.6.0

[visitor@localhost ~]$ npm i –save puppeteer –ignore-scripts

  • puppeteer@1.3.0
    added 41 packages in 4.557s

[visitor@localhost ~]$ vim ~/example.js

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({executablePath: '/opt/google/chrome/chrome',
        headless: false, args: ['--no-sandbox', '--disable-setuid-sandbox']});
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

[visitor@localhost ~]$ node example.js

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页