Selenium 防止检测代码配置

307,654次阅读
没有评论
# 谷歌浏览启动配置
option = webdriver.ChromeOptions()
# 配置参数 禁止 Chrome 正在受到自动化软件控制
option.add_argument('disable-infobars')

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument("--no-sandbox")
options.add_argument("--lang=zh-CN")
options.add_argument(
    'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36')
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome("./chromedriver.exe", chrome_options=options)

driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {"source": """
                          Object.defineProperty(navigator, 'webdriver', {
                          get: () => undefined
                          })
                          """})
liuze
版权声明:本站原创文章,由 liuze2022-04-15发表,共计837字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
载入中...