項目地址:https://github.com/checkly/puppeteer-recorder
官網插件描述:
Chrome extension for recording browser interaction and generating Puppeteer scripts
Puppeteer recorder is a Chrome extension that records your browser interactions and generates a Puppeteer script.
Writing Puppeteer scripts for scraping, testing and monitoring can be tricky. A recorder / code generator can be helpful. This extension has the following features:
- Record clicks, input events etc.
- Pause the recording when navigating.
- Monitor recorded events.
- Export to Puppeteer code.
- Tweak the settings of the generated code.
This extension is actively developed. More events and actions will be added in later versions.
安裝
進入Chrome web store
查找puppeteer recorder
add to chrome
錄製
打開開始錄製
執行
在bing中輸入puppeteer,點擊search,點擊第一個鏈接
停止
錄製的腳本如下:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setViewport({ width: 991, height: 618 })
await page.goto('https://cn.bing.com/?scope=web&FORM=QBRE')
await page.waitForSelector('#sbox > .search_controls > #sb_form > .b_searchboxForm > #sb_form_go')
await page.click('#sbox > .search_controls > #sb_form > .b_searchboxForm > #sb_form_go')
const navigationPromise = page.waitForNavigation()
await navigationPromise
await page.waitForSelector('.b_algo:nth-child(1) > .b_title > h2 > a > strong')
await page.click('.b_algo:nth-child(1) > .b_title > h2 > a > strong')
await navigationPromise
await browser.close()
})()