我正在尝试使用Selenium从LV网站中抓取一些数据,并在单击登录"按钮后继续显示拒绝访问"屏幕.我觉得这是可以防止的,因为当我手动执行相同的操作时,一切似乎都可以正常工作.奇怪的是,我需要单击两次登录"按钮才能手动登录.
I am trying to scrape some data from LV website with Selenium and keep getting 'Access Denied' screen once 'sign in' button clicked. I feel like there is a protection against this because all seems to be working fine when I do the same manually. Oddly, I need to click 'sign in' button twice to be able to sign in manually.
我的代码:
from selenium import webdriver from selenium.webdrivermon.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe') driver.get('secure.louisvuitton/eng-gb/mylv') WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='ucm-wrapper']"))) driver.find_element_by_xpath("//button[@class='ucm-button ucm-button--default ucm-choice__yes']").click() driver.find_element_by_id('loginloginForm').send_keys('xxx@xxx') driver.find_element_by_id ('passwordloginForm').send_keys('xxxxxx') driver.find_element_by_id('loginSubmit_').click()错误:
You don't have permission to access "secure.louisvuitton/eng-gb/mylv;jsessionid=xxxxxxx.front61-prd?" on this server.是否可以使用Selenium登录并绕过此方法?
Is there a way to login with Selenium and bypass this?
推荐答案自从我发布此问题已经有一段时间了,但是下面是否有兴趣的人是我解决该问题的步骤.
It's been a while since I had posted this question but if anyone is interested below are the steps I've taken to solve the problem.
在十六进制编辑器中打开 chromedriver.exe ,找到字符串 $ cdc 并替换为其他相同长度的内容.然后保存并运行修改后的二进制文件.在此答案及其答复中了解更多信息.
Open chromedriver.exe in hex editor, find the string $cdc and replace with something else of the same length. Then save and run modified binary. Read more in this answer and the replies to it.
硒python代码:
options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('--disable-blink-features=AutomationControlled') options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) driver = webdriver.Chrome(options=options, executable_path='chromedriver.exe') driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})") driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 'AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/85.0.4183.102 Safari/537.36'})更多推荐
硒:访问被拒绝
发布评论