我正在构建一个需要安装 metamask 扩展的 selenium 机器人,在访问dextool时,它被 cloudflare bot detection screenshot卡住了。我已经尝试了这些 stackoverflow 问题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)
在那之后我仍然被抓住了,可以帮忙解决这个问题吗?