使用selenium和python保存Chromedriver中的扩展设置

时间:2018-02-19 00:44:20

标签: python selenium web-scraping selenium-chromedriver

我正在使用chromedriver和selenium for python。

我想为扩展程序保存一些设置,以便每次我使用该扩展程序加载chromedriver时设置都会返回。 请参阅下文,我想保存用户名和密码

enter image description here

我目前正在加载扩展,如下所示。

 def __init__(self):
    capa = DesiredCapabilities.CHROME
    capa["pageLoadStrategy"] = "none"

    chrome_options = Options()
    chrome_options.add_extension('/home/simonsays/PycharmProjects/lbc_piscine_spider/chrome_extentions/Cookie-AutoDelete_v2.1.2.crx')
    chrome_options.add_extension('/home/simonsays/PycharmProjects/lbc_piscine_spider/chrome_extentions/Random-User-Agent_v2.1.10.crx')
    chrome_options.add_extension('/home/simonsays/PycharmProjects/lbc_piscine_spider/chrome_extentions/Proxy-Auto-Auth_v2.0.crx')


    self.driver1 = webdriver.Chrome("/var/chromedriver/chromedriver", desired_capabilities=capa,chrome_options=chrome_options)

1 个答案:

答案 0 :(得分:0)

我用个人资料方法解决了我的问题:

    capa = DesiredCapabilities.CHROME
    capa["pageLoadStrategy"] = "none"

    chrome_options = Options()
    chrome_options.add_argument(
        "user-data-dir=/home/simonsays/PycharmProjects/lbc_piscine_spider/chrome_extentions/profile")
    chrome_options.add_argument("--profile-directory=test")

    self.driver = webdriver.Chrome("/var/chromedriver/chromedriver", desired_capabilities=capa

当驱动程序打开时,我会安装我想要的任何扩展名,并将它们保存在我上面定义的配置文件夹中。我想你也可以复制你想要使用的任何现有的个人资料。