【问题标题】:how can I use selenium with my normal browser如何在我的普通浏览器中使用 selenium
【发布时间】:2014-09-21 00:01:06
【问题描述】:

是否可以将 selenium 连接到我通常使用的浏览器而不是驱动程序?对于正常浏览,我使用带有几个插件的 chrome - 添加块加、flashblock 等等。我想尝试使用此特定配置加载站点。我该怎么做?

p.s - 我不想只连接到这个问题中的打开浏览器:

How to connect to an already open browser?

我不在乎是否使用驱动程序生成进程。我只想要完整的浏览器配置 - cookie、插件、字体等。

谢谢

【问题讨论】:

    标签: python python-2.7 selenium


    【解决方案1】:

    首先,您需要下载ChromeDriver,然后将可执行文件的路径放到PATH 环境变量中,或者在executable_path 参数中传递路径:

    from selenium import webdriver
    driver = webdriver.Chrome(executable_path='/path/to/executeable/chrome/driver')
    

    为了加载扩展,你需要设置ChromeOptions:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = webdriver.ChromeOptions()
    options.add_extension('Adblock-Plus_v1.4.1.crx')
    
    driver = webdriver.Chrome(chrome_options=options)
    

    您还可以保存您拥有的 chrome 用户配置文件并将其加载到ChromeDriver

    options = webdriver.ChromeOptions()
    options.add_argument('--user-data-dir=/path/to/my/profile')
    driver = webdriver.Chrome(chrome_options=options)
    

    另见:

    【讨论】:

    • 感谢您的回答。字体呢?我想使用安装在我的 chrome 上的相同字体在我的 webdriver 中浏览。能做到吗?
    • @WeaselFox 我会尝试保存/加载用户配置文件。我已经更新了答案,希望对您有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 2011-05-27
    • 2011-08-09
    相关资源
    最近更新 更多