【发布时间】:2021-07-24 05:41:12
【问题描述】:
出于教育目的,我需要从站点获取一些信息,但是由于保护,我无法发送请求。我得到了典型的 Checking-your-browser 页面首先出现,然后我被反复重定向。 我如何在 python selenium 中绕过这种保护?
【问题讨论】:
标签: python selenium selenium-chromedriver cloudflare
出于教育目的,我需要从站点获取一些信息,但是由于保护,我无法发送请求。我得到了典型的 Checking-your-browser 页面首先出现,然后我被反复重定向。 我如何在 python selenium 中绕过这种保护?
【问题讨论】:
标签: python selenium selenium-chromedriver cloudflare
我很久以前就遇到过这个问题,我能够解决它。使用下面的代码并享受:)
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r"webdriver\chromedriver.exe")
///////// 编辑////////////// 这种方式现在行不通了!
【讨论】:
2021 年 7 月解决方案
只需在 chrome 选项中添加用户代理参数并将用户代理设置为任何值
ops = Options() ua='cat' ops.add_argument('--user-agent=%s' % ua) driver=uc.Chrome(executable_path=r"C:\chromedriver.exe",chrome_options=ops)
【讨论】: