import puppeteer from 'puppeteer' const browser = await puppeteer.launch({headless: false}) const page = await browser.newPage() await page.setDefaultNavigationTimeout(1000 * 60) await page.setRequestInterception(true) page.on('request', async interceptedRequest => { interceptedRequest.continue() }) let contentPromise = new Promise(function (resolve, reject) { page.on('requestfinished', async interceptedRequest => { let url = interceptedRequest.url() if (url.indexOf('interfaceJson')>-1) { let txt = await await interceptedRequest.response()?.text() resolve(txt) } }) }) await page.goto('http://bmfw.www.gov.cn/') await Promise.all([new Promise((resolve) => setTimeout(resolve, 50))]); let content:any = await contentPromise
标签:resolve,nodejs,url,await,接口,interceptedRequest,let,拦截,page From: https://www.cnblogs.com/zyip/p/16993803.html