I was blocked by Cloudflare while scraping some websites and this saved me. So, I am gonna write it down.

TL;DR

options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")

Complete Code Example

from selenium import webdriver

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)
driver.get(URL)

Detail

  • options.add_experimental_option("excludeSwitches", ["enable-automation"])
    • Exclude the collection of enable-automation switches

  • options.add_experimental_option('useAutomationExtension', False)
    • Turn-off useAutomationExtension

  • options.add_argument("--disable-blink-features=AutomationControlled")
    • Make navigator.webdriver=undefined in webdriver console


References


Share


Donation

如果覺得這篇文章對你有幫助, 除了留言讓我知道外, 或許也可以考慮請我喝杯咖啡, 不論金額多寡我都會非常感激且能鼓勵我繼續寫出對你有幫助的文章。

If this blog post happens to be helpful to you, besides of leaving a reply, you may consider buy me a cup of coffee to support me. It would help me write more articles helpful to you in the future and I would really appreciate it.


Related Posts