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
Table of contents 1. Test experiment 2. Performan...
Table of contents What is a Mapping Difference be...
background First of all, I would like to state th...
Serialization implementation InnoDB implements se...
Table of contents Preface 1. Style penetration 1....
Next, we will learn how to monitor server perform...
Table of contents How to deploy MySQL service usi...
<br />Information duplication, information o...
1. nohup Run the program in a way that ignores th...
When using a cloud server, we sometimes connect t...
1. Installation version details Server: MariaDB S...
Here is a text scrolling effect implemented with ...
This article example shares the specific code of ...
Table of contents background explore Summarize ba...
Table of contents What is a web container? The Na...