玩puppeteer
官网
github puppetter
puppetter API
中文版puppetter API
免登录
先找到登录后的Cookies,用这个下载:edit this cookie
(Puppeteer cookie 使用,免登录 )[https://guozh.net/puppeteer-cookie-login/]
how-to-save-cookies-and-load-it-in-another-puppeteer-session
save cookies
const fs = require('fs').promises;
// ... puppeteer code
const cookies = await page.cookies();
await fs.writeFile('./cookies.json', JSON.stringify(cookies, null, 2));
load cookies
const fs = require('fs').promises;
// ... puppeteer code
const cookiesString = await fs.readFile('./cookies.json');
const cookies = JSON.parse(cookiesString);
await page.setCookie(...cookies);
puppeteer-extra
Github 主页
puppeteer-extra是一个monorepo项目,这个框架里面还能再放其他各种插件。
puppeteer-extra-plugin-repl
debug
Google的Puppeteer Debugging
how to debug puppeteer
Youtube:Web Scraping with Node.js & Puppeteer ( rants included, no extra charge)
视频推荐:brilliant
拦截request
Puppeteer拦截某条url并返回其响应内容(场景和方法) API RequestInterception拦截器的使用
await page.setRequestInterception(true);
page.on('request', request => {
request.respond({
status: 404,
contentType: 'text/plain',
body: 'Not Found!'
});
});