zoukankan      html  css  js  c++  java
  • puppeteer 无头浏览器防检测

    async function setBrowserPage(page){
        // 设置user_agent
        await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4181.9 Safari/537.36")
        // 设置webdriver
        await page.evaluateOnNewDocument(() => {
            Object.defineProperty(navigator, 'webdriver', { get: () => false });
            Object.defineProperty(navigator, 'plugins', {
                get: () => [
                    {
                        0: {type: "application/x-google-chrome-pdf", suffixes: "pdf", description: "Portable Document Format", enabledPlugin: Plugin},
                        description: "Portable Document Format",
                        filename: "internal-pdf-viewer",
                        length: 1,
                        name: "Chrome PDF Plugin"
                    },
                    {
                        0: {type: "application/pdf", suffixes: "pdf", description: "", enabledPlugin: Plugin},
                        description: "",
                        filename: "mhjfbmdgcfjbbpaeojofohoefgiehjai",
                        length: 1,
                        name: "Chrome PDF Viewer"
                    },
                    {
                        0: {type: "application/x-nacl", suffixes: "", description: "Native Client Executable", enabledPlugin: Plugin},
                        1: {type: "application/x-pnacl", suffixes: "", description: "Portable Native Client Executable", enabledPlugin: Plugin},
                        description: "",
                        filename: "internal-nacl-plugin",
                        length: 2,
                        name: "Native Client"
                    }
                ],
            });
        });
        await page.evaluateOnNewDocument(() => {
            window.navigator.chrome = {
                runtime: {},
                loadTimes: function() {},
                csi: function() {},
                app: {}
            };
        });
        await page.evaluateOnNewDocument(() => {
            window.navigator.language = {
                runtime: {},
                loadTimes: function() {},
                csi: function() {},
                app: {}
            };
        });
    }
  • 相关阅读:
    Netty回调与Channel执行流程分析
    Netty执行流程分析与重要组件介绍
    HBase 介绍
    Java文件上传下载原理
    ngxtop安装和使用
    开启Nginx监控 with-http_stub_status_module
    Spring 事务模板方法设计模式
    Spring 事务管理
    JdkDynamicAopProxy 拦截器链的获得与递归执行
    CgLib实现AOP
  • 原文地址:https://www.cnblogs.com/zyfeng/p/13677498.html
Copyright © 2011-2022 走看看