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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Python 3.x 警告:使用Selenium Chromedriver Python启用了跨站点请求伪造控制错误_Python 3.x_Selenium_Webdriver_Selenium Chromedriver_Csrf - Fatal编程技术网

Python 3.x 警告:使用Selenium Chromedriver Python启用了跨站点请求伪造控制错误

Python 3.x 警告:使用Selenium Chromedriver Python启用了跨站点请求伪造控制错误,python-3.x,selenium,webdriver,selenium-chromedriver,csrf,Python 3.x,Selenium,Webdriver,Selenium Chromedriver,Csrf,我无法使用driver.get()直接导航到网页https://example.com) 网站将显示一条消息: 警告:已启用跨站点请求伪造控制 但如果我使用Selenium的ActionChains实现 ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform() 我可以成功地通过网站导航到新的网页 我尝试过保存和恢复cookies。他没有成功 我还需要做什么,才能使用driver.get()导航到网站的不

我无法使用
driver.get()直接导航到网页https://example.com)

网站将显示一条消息:

警告:已启用跨站点请求伪造控制

但如果我使用Selenium的ActionChains实现

ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
我可以成功地通过网站导航到新的网页

我尝试过保存和恢复cookies。他没有成功

我还需要做什么,才能使用
driver.get()
导航到网站的不同网页?

跨网站请求伪造(CSRF) 是一种攻击,迫使最终用户在其当前已通过身份验证的web应用程序上执行不需要的操作。CSRF攻击的目标是改变状态的请求,而不是窃取数据,因为攻击者无法看到对伪造请求的响应。借助社会工程(如通过电子邮件或聊天发送链接),攻击者可以诱使web应用程序的用户执行攻击者选择的操作。如果受害者是普通用户,成功的CSRF攻击会迫使用户执行状态更改请求,如转账、更改其电子邮件地址等。如果受害者是一个管理帐户,CSRF可能会破坏整个web应用程序

因此,当您使用Selenium的
ActionChains
实现时:

ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
假设您正在访问另一个网页,其中建立了一个会话,并验证了许多其他会话属性。在下一步中,您将使用Selenium的
ActionChains
实现在Web元素上调用
click()
,该Web元素将带您进入新网页
https://example.com

但在另一种方法中,您尝试直接导航到网页
https://example.com
其中所需的会话属性不存在。因此,本例中的会话未建立,您将看到以下警告:

解决方案 更简单的解决方案是遵循实际流程,即访问初始网页,在该网页中建立会话并验证所需的会话属性。在下一步中,您可以使用Selenium的ActionChains实现在所需的WebElement上调用
click()
,将您带到新网页

可供替代的
另一种选择是,您可以根据自己的需求存储和重用。是的,我理解这一点,但我的问题是如何/如何传递这些必需的“会话属性”,以便成功使用
驱动程序。获取https://example.com)
。我需要在
driver.get()
请求的url中灵活地发送参数。@HarshGoyal检查答案更新,并告诉我这是否回答了您的问题。
Warning: cross-site request forgery control is enabled