如何在Chrome驱动程序中重复使用Selenium预装的图像?

时间:2017-06-21 06:09:17

标签: python google-chrome selenium

我正在使用Selenium框架和Python,我试图通过在我的Python代码中重用Chrome webdriver中预装的图像来实现自动化,从而节省带宽。我能够访问图像的源URL,到目前为止,我只是使用 requests 重新重新加载它们。我确定普通的浏览器将图像保存到硬盘上的临时位置,我想Chrome webdriver也是如此。如果我知道src?

,如何使用Selenium访问这些文件

1 个答案:

答案 0 :(得分:2)

您应该重复使用Chrome配置文件,例如:

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

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\path\\to\\your\\profile")  # Path to your chrome profile
driver = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)

关于路径,可以通过转到Chrome中的chrome://version/来完成此操作,其中一个设置就是路径,这将重用您的chrome配置文件,您可能需要从路径中删除最后一个目录如果它是Default目录。

如果您想要自己的配置文件未连接到您的Chrome,您可以指定所需的任何路径,selenium将为您创建。