Selenium Python-CORS问题
我正试图使用Selenium Python登录到我的dvd.netflix帐户,但我一直收到不正确的登录信息(尽管输入了正确的用户名和密码),因为由于cors错误,身份验证请求失败 这是我正在使用的代码:Selenium Python-CORS问题,python,selenium,selenium-webdriver,cors,webdriverwait,Python,Selenium,Selenium Webdriver,Cors,Webdriverwait,我正试图使用Selenium Python登录到我的dvd.netflix帐户,但我一直收到不正确的登录信息(尽管输入了正确的用户名和密码),因为由于cors错误,身份验证请求失败 这是我正在使用的代码: from selenium import webdriver import time driver = webdriver.Chrome() driver.get('https://dvd.netflix.com/SignIn') username_input = '//*[@id=&q
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get('https://dvd.netflix.com/SignIn')
username_input = '//*[@id="email"]'
password_input = '//*[@id="password"]'
login_submit = '//*[@id="signin"]/button'
driver.find_element_by_xpath(username_input).send_keys("justtest0219@gmail.com")
driver.find_element_by_xpath(password_input).send_keys("12345")
driver.find_element_by_xpath(login_submit).click()
我得到的错误是:
Access to XMLHttpRequest at 'https://portal.dvd.netflix.com/auth/authenticate' from origin 'https://dvd.netflix.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
我还尝试禁用CORS检查,但仍然无法登录,如果我尝试使用WebDriver for Chrome手动登录,它确实会登录可能是您尝试调用
send_keys()
太早,甚至在启动之前
要将字符序列发送到需要为导出的元素,可以使用以下任一方法:
- 使用
:XPATH
driver.get('https://dvd.netflix.com/SignIn') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']"))).send_keys("justtest0219@gmail.com")
- 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
--禁用闪烁功能=自动控制
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://dvd.netflix.com/SignIn')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='email']"))).send_keys("justtest0219@gmail.com")
工具书类 您可以在以下内容中找到一些相关的详细讨论: