【问题标题】:Python3, Selenium and Chrome portablePython3、Selenium 和 Chrome 可移植
【发布时间】:2018-03-12 11:59:18
【问题描述】:

可能有人可以在 Windows、Python、Selenium 和使用 Chrome 网络驱动程序和 ChromePortable 方面提供帮助。

我已经定义了一个新文件夹

c:\我的项目

在这个文件夹中,wedriver 位于: c:\myproject\driver\chromedriver.exe

还有 Chrome 便携版

c:\myproject\chromeportable\chrome.exe

现在我想构建一个简单的 Python 脚本,它可以打开 - 比如说 - stackoverflow.com。

在安装了谷歌的计算机上,这不是问题

from selenium import webdriver
driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe")
driver.get("https://stackoverflow.com")

但是,如果没有安装谷歌浏览器并且应该使用谷歌浏览器便携版,如何更改脚本?

有什么想法吗? 非常感谢您,祝您有美好的一天 安德烈亚斯

【问题讨论】:

    标签: python-3.x selenium-webdriver selenium-chromedriver


    【解决方案1】:

    使用选项类:

    from selenium.webdriver.chrome.options import Options
    options = Options()
    options.binary_location = "c:\myproject\chromeportable\chrome.exe"
    # you may need some other options
    #options.add_argument('--no-sandbox')
    #options.add_argument('--no-default-browser-check')
    #options.add_argument('--no-first-run')
    #options.add_argument('--disable-gpu')
    #options.add_argument('--disable-extensions')
    #options.add_argument('--disable-default-apps')
    driver = webdriver.Chrome("c:\myproject\driver\chromedriver.exe",
                options=options)
    

    【讨论】:

    • 非常感谢!你让我开心:o)
    • 还有一个问题!谷歌浏览器便携式识别不是 click() 事件。任何的想法?如果我使用与本地安装的 chome 浏览器(非便携式版本)相同的代码,则它可以工作。非常感谢您提前问候安德烈亚斯
    猜你喜欢
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    相关资源
    最近更新 更多