项目作者: puppeteer

项目描述 :
Headless Chrome Node.js API
高级语言: TypeScript
项目地址: git://github.com/puppeteer/puppeteer.git
创建时间: 2017-05-09T22:16:13Z
项目社区:https://github.com/puppeteer/puppeteer

开源协议:Apache License 2.0

下载


Puppeteer

build
npm puppeteer package

Puppeteer is a JavaScript library which provides a high-level API to control
Chrome or Firefox over the
DevTools Protocol or WebDriver BiDi.
Puppeteer runs in the headless (no visible UI) by default

Get started | API | FAQ | Contributing | Troubleshooting

Installation

```bash npm2yarn
npm i puppeteer # Downloads compatible Chrome during installation.
npm i puppeteer-core # Alternatively, install as a library, without downloading Chrome.

  1. ## Example
  2. ```ts
  3. import puppeteer from 'puppeteer';
  4. // Or import puppeteer from 'puppeteer-core';
  5. // Launch the browser and open a new blank page
  6. const browser = await puppeteer.launch();
  7. const page = await browser.newPage();
  8. // Navigate the page to a URL.
  9. await page.goto('https://developer.chrome.com/');
  10. // Set screen size.
  11. await page.setViewport({width: 1080, height: 1024});
  12. // Type into search box using accessible input name.
  13. await page.locator('aria/Search').fill('automate beyond recorder');
  14. // Wait and click on first result.
  15. await page.locator('.devsite-result-item-link').click();
  16. // Locate the full title with a unique string.
  17. const textSelector = await page
  18. .locator('text/Customize and automate')
  19. .waitHandle();
  20. const fullTitle = await textSelector?.evaluate(el => el.textContent);
  21. // Print the full title.
  22. console.log('The title of this blog post is "%s".', fullTitle);
  23. await browser.close();