gpt4 book ai didi

python-3.x - 如何在 python selenium 中设置 Chrome 实验性选项 same-site-by-default-cookie

转载 作者:行者123 更新时间:2023-12-02 00:08:35 24 4
gpt4 key购买 nike

我想这应该可行:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('same-site-by-default-cookies', 'true')
driver = webdriver.Chrome(chrome_options=options)

为 future 的 chrome 版本启用 samesite cookies 限制。不是,有错误:

selenium.common.exceptions.InvalidArgumentException: 
Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: same-site-by-default-cookies

我可以使用 chrome://flags 手动更改选项并查看它是否正常工作。但是我想自动化它并运行测试脚本来查看它。

这里有java代码:https://groups.google.com/forum/#!topic/chromedriver-users/cI8hj7eihRo这可以做到,但我不确定如何将它转移到 python。

是否有任何引用资料可以帮助我设置此选项或不同的选项?

最佳答案

在 Chrome 上测试:版本 79.0.3945.130(官方构建)(64 位)

在Python中你可以使用下面的代码

    chrome_options = webdriver.ChromeOptions()
experimentalFlags = ['same-site-by-default-cookies@1','cookies-without-same-site-must-be-secure@1']
chromeLocalStatePrefs = { 'browser.enabled_labs_experiments' : experimentalFlags}
chrome_options.add_experimental_option('localState',chromeLocalStatePrefs)
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://www.bing.com")

Python selenium 客户端将发送如下功能

[1579581631.792][INFO]: Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})
[1579581631.792][INFO]: Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1579581632.264][INFO]: [f6b8433509c420fd317902f72b1d102d] COMMAND InitSession {
"capabilities": {
"alwaysMatch": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ ],
"extensions": [ ],
"localState": {
"browser.enabled_labs_experiments": [ "same-site-by-default-cookies@1", "cookies-without-same-site-must-be-secure@1" ]
}
},
"platformName": "any"
},
"firstMatch": [ {

} ]
},
"desiredCapabilities": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ ],
"extensions": [ ],
"localState": {
"browser.enabled_labs_experiments": [ "same-site-by-default-cookies@1", "cookies-without-same-site-must-be-secure@1" ]
}
},
"platform": "ANY",
"version": ""
}
}

检查它是否真的有效。转到 chrome://flags/

关于python-3.x - 如何在 python selenium 中设置 Chrome 实验性选项 same-site-by-default-cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59787776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com