【问题标题】:Accesssing Corsair.com with Python Selenium?使用 Python Selenium 访问 Corsair.com?
【发布时间】:2022-01-25 16:35:03
【问题描述】:

是否可以在 Python 中使用 Selenium 访问 https://www.corsair.com/ 而不会被 Corsair 阻止?

当我尝试在 Selenium 中加载页面时,它一直给我这个错误消息:

我试图绕过它,将用户代理更改为随机的,这并没有解决问题。

这是我的代码:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from fake_useragent import UserAgent


options = webdriver.ChromeOptions()
options.add_argument("window-size=1400,600")
ua = UserAgent()
user_agent = ua.random
print(user_agent)
options.add_argument(f'user-agent={user_agent}')
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)

print('Loading Corsair Website ...')
driver.get("https://www.corsair.com/")

【问题讨论】:

  • 在我最初的运行中,它有效,但在随后的运行之后,他们的网站以某种方式检测到它是自动化软件。通常在这些情况下修改用户代理对我有帮助。
  • @GevorgChobanyan 是的,当我第一次尝试它时,它也能正常工作,但经过多次尝试,它没有。您是否尝试将我的代码与随机用户代理一起使用?它对你有用吗?

标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

有多种方法可以规避Selenium 自动化检测,其中之一是使用以下参数:

代码块:

options = Options()
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.corsair.com/")
driver.save_screenshot("image.png")

截图:

【讨论】:

  • 不幸的是,我仍然收到相同的错误消息。我没有用服务做到这一点
  • @AndreSolbach 使用或不使用 Service 无关紧要。我已经连续 5 次成功点击 url,没有任何问题。
猜你喜欢
  • 1970-01-01
  • 2019-05-10
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-20
  • 2021-06-10
  • 2021-04-28
相关资源
最近更新 更多