Skip to main content
Version: 23.10.1

安装

¥Installation

要在项目中使用 Puppeteer,请运行:

¥To use Puppeteer in your project, run:

npm i puppeteer

当你安装 Puppeteer 时,它会自动下载最新版本的 用于测试的 Chrome(~170MB macOS、~282MB Linux、~280MB Windows)和 chrome-headless-shell 二进制文件(从 Puppeteer v21.6.0 开始),即带有 Puppeteer 的 保证能用于。浏览器默认下载到 $HOME/.cache/puppeteer 文件夹(从 Puppeteer v19.0.0 开始)。请参阅 configuration 了解用于控制下载行为的配置选项和环境变量。

¥When you install Puppeteer, it automatically downloads a recent version of Chrome for Testing (~170MB macOS, ~282MB Linux, ~280MB Windows) and a chrome-headless-shell binary (starting with Puppeteer v21.6.0) that is guaranteed to work with Puppeteer. The browser is downloaded to the $HOME/.cache/puppeteer folder by default (starting with Puppeteer v19.0.0). See configuration for configuration options and environmental variables to control the download behavior.

对于 v1.7.0 以来的每个版本,我们都会发布两个包:

¥For every release since v1.7.0 we publish two packages:

puppeteer 是一款浏览器自动化产品。安装后,它会下载一个 Chrome 版本,然后使用 puppeteer-core 驱动该版本。作为终端用户产品,puppeteer 使用合理的 可以定制的 默认值自动执行多个工作流程。

¥puppeteer is a product for browser automation. When installed, it downloads a version of Chrome, which it then drives using puppeteer-core. Being an end-user product, puppeteer automates several workflows using reasonable defaults that can be customized.

puppeteer-core 是一个帮助驱动任何支持 DevTools 协议的库。作为一个库,puppeteer-core 完全通过其编程接口驱动,这意味着不采用默认值,并且 puppeteer-core 在安装时不会下载 Chrome。

¥puppeteer-core is a library to help drive anything that supports DevTools protocol. Being a library, puppeteer-core is fully driven through its programmatic interface implying no defaults are assumed and puppeteer-core will not download Chrome when installed.

如果你是 连接到远程浏览器自己管理浏览器,则应使用 puppeteer-core。如果你自己管理浏览器,则需要使用显式 executablePath 调用 puppeteer.launch(如果安装在标准位置,则调用 channel)。

¥You should use puppeteer-core if you are connecting to a remote browser or managing browsers yourself. If you are managing browsers yourself, you will need to call puppeteer.launch with an explicit executablePath (or channel if it's installed in a standard location).

使用 puppeteer-core 时,记得更改导入:

¥When using puppeteer-core, remember to change the import:

import puppeteer from 'puppeteer-core';