puppeteer recorder使用说明

Python 362 2018-09-14 15:59

项目地址: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


puppeteer recorder使用说明-JEESNS

add to chrome

添加成功后出现
puppeteer recorder使用说明-JEESNS

录制
打开开始录制
puppeteer recorder使用说明-JEESNS

执行

在bing中输入puppeteer,点击search,点击第一个链接
停止


puppeteer recorder使用说明-JEESNS

录制的脚本如下:
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()
})()

文章评论