You may encounter the following problems when installing puppeteer on Linux. This article will guide you how to get out of the pit!
The process I successfully installed puppeteer and actually took screenshots is as follows: 1. Install nodejs and npm # Download and decompress wget -c https://nodejs.org/dist/v8.9.1/node-v8.9.1-linux-x64.tar.xz tar -xvf node-v8.9.1-linux-x64.tar.xz # Move and rename (optional) mv node-v8.9.1-linux-x64 /www/nodejs # Create a soft link (shortcut). If the name in the previous step is different, adjust the underlined part of this step according to the actual situation. ln -s /www/nodejs/bin/node /usr/local/bin/node ln -s /www/nodejs/bin/npm /usr/local/bin/npm 2. Install chromium 3. Install puppeteer-core (direct installation of puppeteer will result in an error because chromium cannot be downloaded) 4. Create a new a.js const puppeteer = require('puppeteer-core'); (async () => { const browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium-browser', args:["--no-sandbox"] }); const page = await browser.newPage(); await page.goto('https://www.baidu.com'); await page.screenshot({path: 'example.png'}); await browser.close(); })(); The code in this step may be different from the one on the Internet. One is that the code in require is puppeteer-core instead of puppeteer, because we installed puppeteer-core instead of puppeteer The other is that there are two parameters in launch. The first parameter is also because we did not install puppeteer directly, so we need to specify the path. The second parameter is due to some limitations of chromium, and the root account needs to add this parameter to execute 5. Execute a.js After execution, you can see an example.png Note: If there is Chinese on the page, it may not display properly due to the lack of Chinese fonts. The solution is to directly upload the Chinese fonts in c:/windows/fonts on your computer to /usr/share/fonts/chinese on the server (there is no Chinese directory by default, so you can create one yourself). : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : Puppeter related documents https://pptr.dev/ Summarize The above is what I introduced to you about using puppeteer on Linux (centos) to realize the webpage screenshot function. I hope it will be helpful to you! You may also be interested in:
|
<<: A brief discussion on the implementation principle of Vue slot
>>: Detailed explanation of MySQL remote connection permission
This article shares with you a practical web navi...
This article mainly introduces the implementation...
I recently wanted to convert a website to https a...
Table of contents Preface Related Materials Achie...
Table of contents Overview 1. RangeError 2. Refer...
Table of contents 1. Database Operation 2. Data T...
First query table structure (sys_users): SELECT *...
Awk is a powerful tool that can perform some task...
Detailed explanation and examples of database acc...
Sometimes you need to debug remotely in a server ...
Table of contents Quick Start How to use Core Pri...
Table of contents Zabbix custom monitoring nginx ...
Preface As you all know, we have encountered many...
Before the release of Microsoft IE 5.0, the bigges...
In fact, the three tables above all have three ro...