使用 Selenium 自动结账过程时出现 403 [英] Getting 403 when using Selenium to automate checkout process
问题描述
我正在尝试使用 python 和 selenium 创建一个脚本,以在 bestbuy.ca 上自动执行结账流程.
我一路走到最后一步,您点击查看最终订单,但当我尝试点击进入最后一步时,收到以下 403 禁止消息(如网络响应中所示).
是否有服务器端检测到我正在使用 selenium 并阻止我继续?
如何隐藏使用硒的事实?
这些是我用于 selenium 的选项:
options = Options()options.add_argument('--disable-blink-features=AutomationControlled')options.add_argument(开始最大化")options.add_argument("--disable-extensions")驱动程序 = webdriver.Chrome(选项=选项)
我目前在每个操作(即打开页面、等待、点击添加到购物车、等待、点击结账、等待)后有 10 秒的延迟
我已经实现了在每次运行时使用的随机用户代理:
import fake_useragentua = 用户代理()用户代理 = ua.randomoptions.add_argument(f'user-agent={userAgent}')
我还根据
经过过去几天的大量测试,这里有一些选项可以让我绕过我面临的限制.
Chrome 驱动程序选项:
options.add_argument('--disable-blink-features=AutomationControlled')options.add_argument("--disable-extensions")options.add_experimental_option('useAutomationExtension', False)options.add_experimental_option("excludeSwitches", ["enable-automation"])chrome_driver = webdriver.Chrome(options=options)
将 webdriver 导航器的属性值更改为 undefined:
chrome_driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
在实现所有这三个之后,我在浏览网站和购物车/结帐流程时不再遇到任何 403 错误.
I am trying to create a script using python and selenium to automate the checkout process at bestbuy.ca.
I get all the way to the final stage where you click to review the final order, but get the following 403 forbidden message (as seen in the network response) when I try to click through to the final step.
Is there something server side that has detected that I am using selenium and preventing me to proceed?
How can I hide the fact that it is selenium being used?
These are the options I am using for selenium:
options = Options()
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("start-maximized")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(options=options)
I currently have 10 second delays after each action(ie open page, wait, click add to cart, wait, click checkout, wait)
I have implemented a random useragent to be used on each run:
import fake_useragent
ua = UserAgent()
userAgent = ua.random
options.add_argument(f'user-agent={userAgent}')
I have also modified my chromedriver binary as per the comments in THIS THREAD
Error seen when proceeding to order review page:
After much testing the last few days, here are the options that have allowed me to bypass the restrictions I was facing.
Chromedriver options:
options.add_argument('--disable-blink-features=AutomationControlled') options.add_argument("--disable-extensions") options.add_experimental_option('useAutomationExtension', False) options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_driver = webdriver.Chrome(options=options)
Change the property value of the navigator for webdriver to undefined:
chrome_driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
After all three of these were implemented I no longer faced any 403 error when navigating the site and the cart/checkout process.
这篇关于使用 Selenium 自动结账过程时出现 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!