我在尝试使用 chrome 驱动程序和 selenium 访问网站 (bet365.com) 时遇到了一些麻烦(我被“阻止”了)。
我可以使用普通的 chrome 访问该站点,但是当我尝试使用 chrome 驱动程序时,它不起作用。
我之前遇到过这个问题,并通过使用以下一些选项(python)来纠正它:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'PATH_TO\chromedriver.exe')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
driver.execute_cdp_cmd("Network.enable", {})
driver.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'})
driver.get("https://www.bet365.com/")
现在,问题又回来了,此代码不再起作用以绕过保护。有人能帮我吗?
最佳答案
万一Selenium驱动 ChromeDriver发起 google-chrome正在检测到浏览上下文潜在的解决方案是使用 undetected-chromedriver初始化 Chrome 浏览上下文。
undetected-chromedriver是一个优化的 Selenium Chromedriver 补丁,它不会触发像 Distill Network/Imperva/DataDome/Botprotect.io 这样的反机器人服务。它会自动下载驱动程序二进制文件并修补它。
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = uc.Chrome(options=options)
driver.get('https://bet365.com')
引用
您可以在以下位置找到一些相关的详细讨论:
关于python - 被带有 selenium 和 chromedriver 的网站阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66092682/