selenium bot版本92被cloudflare卡住

2024-10-05 22:00:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个需要安装metamask扩展的selenium机器人,在访问dextool时,它会被cloudflare机器人检测screenshot卡住。 我已经尝试了这些问题中提到的每一件事1&2&3

我上的最后一堂机器人课是:

class Bot:
def __init__(self):
    self.options = webdriver.ChromeOptions()
    self.options.add_argument("start-maximized")
    self.options.add_argument("--disable-blink-features")
    self.options.add_argument("--disable-blink-features=AutomationControlled")
    self.options.add_argument("--disable-gpu")
    self.options.add_argument("--no-sandbox")
    self.options.add_argument(
        "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
    )
    self.options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "safebrowsing-disable-download-protection", "safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])

    self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
    self.options.add_experimental_option("useAutomationExtension", False)
    self.options.add_extension(extension_path)
    self.bot = webdriver.Chrome(options=self.options, executable_path=chrome_path)
    self.bot.execute_script(
        "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
    )
    # self.bot.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36'})
    self.bot.execute_cdp_cmd(
        "Page.addScriptToEvaluateOnNewDocument",
        {
            "source": "const newProto = navigator.__proto__;"
            "delete newProto.webdriver;"
            "navigator.__proto__ = newProto;"
        },
    )
    self.wait = WebDriverWait(self.bot, 20)

在那之后,我还是会被抓住,有人能帮我吗


Tags: pathselfaddnavigatorexecutebot机器人chrome