Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Python-CORS问题_Python_Selenium_Selenium Webdriver_Cors_Webdriverwait - Fatal编程技术网

Selenium Python-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

我正试图使用Selenium Python登录到我的dvd.netflix帐户,但我一直收到不正确的登录信息(尽管输入了正确的用户名和密码),因为由于cors错误,身份验证请求失败

这是我正在使用的代码:

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")

工具书类 您可以在以下内容中找到一些相关的详细讨论:


我通过使用firefox geckodriver而不是chrome webdriver解决了这个问题。用您看到的错误更新问题。完成。控制台日志中有错误。仍将收到相同的错误。如果我使用selenium打开登录页面并手动填写表单,它就会工作。即使我只使用selenium和密码手动填写电子邮件,或者只定义find_element_by_uu。。。我得到了错误。@EmmaGrove可能是由于分区限制,我得到了一个即使手动访问页面也找不到的页面。因此提供了一些其他参考资料供您参考。非常感谢您的帮助!该网站在某些国家不可用。使用USA Vpn,如果你有,如果你没有,我可以给你mine@EmmaGrove当然让我们在内部详细讨论这个问题,您没有回应