【问题标题】:Save settings for extentions in Chromedriver using selenium with python使用 selenium 和 python 在 Chromedriver 中保存扩展的设置
【发布时间】:2018-07-29 05:15:45
【问题描述】:

我正在为 python 使用带有 selenium 的 chromedriver。

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

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

 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)

【问题讨论】:

  • 程序每次运行时都必须使用空白配置文件吗?如果没有,请考虑在另一个配置文件/默认配置文件中加载 extension。阅读this 以供参考。这样,为该配置文件保存的设置/扩展应该在每次启动程序时加载。

标签: python selenium web-scraping selenium-chromedriver


【解决方案1】:

我用配置文件方法解决了我的问题:

    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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 2017-08-22
    • 2018-10-21
    相关资源
    最近更新 更多