PuppeteerNode 类
¥PuppeteerNode class
使用用于获取和下载浏览器的 Node 特定行为扩展主 Puppeteer 类。
¥Extends the main Puppeteer class with Node specific behaviour for fetching and downloading browsers.
如果你在 Node 环境中使用 Puppeteer,则这是你在运行 require('puppeteer')
(或等效的 ES import
)时获得的类。
¥If you're using Puppeteer in a Node environment, this is the class you'll get when you run require('puppeteer')
(or the equivalent ES import
).
签名:
¥Signature:
export declare class PuppeteerNode extends Puppeteer
Extends: Puppeteer
备注
¥Remarks
最常用的方法是 launch,它用于启动并连接到新的浏览器实例。
¥The most common method to use is launch, which is used to launch and connect to a new browser instance.
所有环境通用的方法请参见 主 Puppeteer 类,例如 Puppeteer.connect()。
¥See the main Puppeteer class for methods common to all environments, such as Puppeteer.connect().
此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 PuppeteerNode
类的子类。
¥The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the PuppeteerNode
class.
示例
¥Example
以下是使用 Puppeteer 驱动自动化的典型示例:
¥The following is a typical example of using Puppeteer to drive automation:
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.google.com');
// other actions...
await browser.close();
})();
创建 page
后,你就可以访问大量 API 来与页面交互、导航或查找该页面中的某些元素。page
文档 列出了所有可用的方法。
¥Once you have created a page
you have access to a large API to interact with the page, navigate, or find certain elements in that page. The page
documentation lists all the available methods.
属性
¥Properties
属性 | 修饰符 | 类型 | 描述 |
---|---|---|---|
defaultProduct |
| 默认情况下启动的浏览器的名称。对于 | |
lastLaunchedProduct |
| 最后启动的浏览器的名称。 | |
product |
| string |
方法
¥Methods
方法 | 修饰符 | 描述 |
---|---|---|
此方法将 Puppeteer 附加到现有浏览器实例。 | ||
默认可执行路径。 | ||
在指定时启动具有给定参数和选项的浏览器实例。 与 | ||
删除由提供的 Puppeteer 配置标识的缓存目录中的所有非当前 Firefox 和 Chrome 二进制文件。当前浏览器版本是通过解析 Puppeteer 中的 PUPPETEER_REVISIONS 来确定的,除非提供了 |