PHP笔记网

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2023-07-10 13:14:59  修改时间:2024-11-22 01:10:19  分类:03.数据采集/爬虫  编辑

有开发者给 puppeteer 写了一套插件(10多个插件),叫做puppeteer-extra。其中,就有一个插件叫做puppeteer-extra-plugin-stealth。这个东西,就来专门用来让 puppeteer 隐藏模拟浏览器的指纹特征。

 

puppeteer-extra-plugin-stealth:[Github地址] A plugin for puppeteer-extra and playwright-extra to prevent detection.

Install

npm install puppeteer-extra-plugin-stealth

If this is your first puppeteer-extra plugin here's everything you need:

npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

Usage

// puppeteer-extra is a drop-in replacement for puppeteer,
// it augments the installed puppeteer with plugin functionality
const puppeteer = require('puppeteer-extra')

// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())

// puppeteer usage as normal
puppeteer.launch({ headless: true }).then(async browser => {
  console.log('Running tests..')
  const page = await browser.newPage()
  await page.goto('https://bot.sannysoft.com')
  await page.waitForTimeout(5000)
  await page.screenshot({ path: 'testresult.png', fullPage: true })
  await browser.close()
  console.log(`All done, check the screenshot. ✨`)
})