【问题标题】:Detected on Headless Chrome Selenium在 Headless Chrome Selenium 上检测到
【发布时间】:2022-01-14 10:29:04
【问题描述】:

我试图在使用最新的 UserAgent 无头运行时刮掉亚马逊,但我的速率受到限制。当我 # 退出无头线路时,我不会被检测到或速率受限。下面是我的代码!

options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option("useAutomationExtension", False)
#options.add_argument("--headless")
options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36")
service = ChromeService(executable_path=ChromeDriverManager().install())
browser = webdriver.Chrome(service=service, options=options)
browser.get("https://www.amazon.com.au/Oculus-Quest-2-Virtual-Reality-Headset/dp/B08FSZ8QWH")
print(browser.page_source)

当我在 options.add_argument("--headless") 删除 # 并运行代码时,我得到一个服务器忙线。有人知道解决办法吗?

【问题讨论】:

    标签: python selenium selenium-chromedriver google-chrome-headless rate-limiting


    【解决方案1】:

    avoid detection使用通过add_argument()添加以下参数如下:

    --disable-blink-features=AutomationControlled

    示例代码:

    options = Options()
    options.headless = True
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    options.add_experimental_option('useAutomationExtension', False)
    options.add_argument('--disable-blink-features=AutomationControlled')
    s = Service('C:\\BrowserDrivers\\chromedriver.exe')
    driver = webdriver.Chrome(service=s, options=options)
    driver.get("https://www.amazon.com.au/Oculus-Quest-2-Virtual-Reality-Headset/dp/B08FSZ8QWH")
    

    【讨论】:

    • 如果我把它放在 options.add_experimental_option() 我得到一个错误 TypeError: ChromiumOptions.add_experimental_option() missing 1 required positional argument: 'value' 我只需要把它放在 options.add_argument 中吗?
    • @HKGaming 我的错,逐字输入错误。更新了,应该是add_argument()
    • Perfect 似乎正在工作,非常感谢!
    猜你喜欢
    • 2017-03-04
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 2020-04-16
    • 2021-09-18
    • 2018-07-15
    • 2017-12-26
    • 1970-01-01
    相关资源
    最近更新 更多