在Chrome更新到版本‘122.0.6261.70’之后,我无法使用Selify(Python)测试文件下载.

之前在Chrome上运行的"--Allow-Running-Insecure-Content"Arg做了一个小把戏.网上也有同样的建议.在一些网站上,建议增加一个参数:"--Disable-Web-Security".

但这两件事对我都没有什么影响(警告一直在出现).

有人知道121版和122版之间有什么变化吗?

我是不是遗漏了什么Arg或Pref?

参考的警告图像:

enter image description here


Driver creation (simplified):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
for arg in ["--allow-running-insecure-content", "--disable-web-security"]:
    options.add_argument(arg)
driver = webdriver.Chrome(options=options)

推荐答案

好吧,所以我找到了一个解决方案.

应采取以下措施:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--allow-running-insecure-content")  # Allow insecure content
chrome_options.add_argument("--unsafely-treat-insecure-origin-as-secure=http://example.com")  # Replace example.com with your site's domain (this is what worked for me)
chrome_options.add_experimental_option("prefs", {
    "download.default_directory": download_path,
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "safebrowsing.enabled": True
})

driver = webdriver.Chrome(options=chrome_options)

如果这个管用,请告诉我.

Python相关问答推荐

如何在BeautifulSoup中链接Find()方法并处理无?

Pandas 在最近的日期合并,考虑到破产

使用新的类型语法正确注释ParamSecdecorator (3.12)

Python上的Instagram API:缺少client_id参数"

将输入管道传输到正在运行的Python脚本中

log 1 p numpy的意外行为

计算组中唯一值的数量

什么是最好的方法来切割一个相框到一个面具的第一个实例?

启动带有参数的Python NTFS会导致文件路径混乱

剪切间隔以添加特定日期

在方法中设置属性值时,如何处理语句不可达[Unreacable]";的问题?

比Pandas 更好的 Select

Python日志(log)模块如何在将消息发送到父日志(log)记录器之前向消息添加类实例变量

使用tqdm的进度条

如何使用pytest在traceback中找到特定的异常

如何在Quarto中的标题页之前创建序言页

在Pandas 中以十六进制显示/打印列?

Numpy`astype(Int)`给出`np.int64`而不是`int`-怎么办?

用LAKEF划分实木地板AWS Wrangler

PyTorch变压器编码器中的填充掩码问题