Nodejs后端自动化测试
作者:互联网
偶然看到收藏一下
const puppeteer = require('puppeteer'); const fs = require('fs'); (async () => { const browser = await puppeteer.launch({ headless: true }) const page = await browser.newPage(); await page.goto('https://juejin.im'); await page.waitFor(1000); await page.evaluate(async () => { window.scrollTo(0,document.querySelector('.entry-list').scrollHeight); }); await page.waitFor(500); await page.evaluate(async () => { window.scrollTo(0,document.querySelector('.entry-list').scrollHeight); }); await page.waitFor(500); const res = await page.evaluate(async () => { window.scrollTo(0,document.querySelector('.entry-list').scrollHeight) window.scrollTo(0,document.querySelector('.entry-list').scrollHeight) return [].map.apply(document.querySelectorAll('.info-row.title-row .title'),[v => ({ title:v.innerText, link:v.href, })]) }); fs.writeFileSync('juejin.txt',JSON.stringify(res)); browser.close(); })()
标签:const,后端,scrollTo,await,querySelector,自动化,Nodejs,document,page 来源: https://www.cnblogs.com/sugartang/p/11631720.html