Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use puppeteer in function calculation

Shulou Source: shulou.com Published: 2022-06-02 23:08:08 11月12日 Update

This article mainly introduces how to use puppeteer in function calculation, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

Using puppeteer combined with function calculation, you can quickly build flexible services to complete various functions, including:

Generate a screenshot of a web page or PDF

Advanced crawler that can crawl a large number of web pages that render content asynchronously

Simulate keyboard input, automatic form submission, login web page, etc., to realize UI automatic test.

Capture the timeline of the site to track your site and help analyze site performance problems

Next, we will develop our own puppeteer project based on a scaffolding project.

Download the project

> git clone-o starter-kit https://github.com/awesome-fc/puppeteer-fc-starter-kit.git your_project_name

Project structure

The shared libraries that ├── lib chrome headless depends on are copied to the root directory of the packaged project when packaged.

├── chrome

│ ├── buildChrome.sh compiles the chrome headless shell script, based on which you can compile the latest version

Chrome headless binary package file compiled by │ └── headless_shell.tar.gz

├── src

│ ├── index.js function call entry file, function handler is index.handler, and your business code is written here

│ └── starter-kit

│ ├── config.js acquires relevant configuration properties through environment variables, such as chrome execution directory and installation directory

│ ├── local.js locally tests whether the API of the operation chrome headless is correct, by executing the command: npm run local

│ └── setup.js installs chrome headless-related logic code, such as OSS-based installation or local directory installation

├── package.json

The └── package.zip output function calculates the package file through the command: npm run package or npm run package-nochrome

How to write business code

Index.js file

Cost

Thank you for reading this article carefully. I hope the article "how to use puppeteer in function calculation" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Function project file article code directory web page compilation business command website help test configuration advanced next binary value entry interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Docker NVidia Shulou Information MariaDB