在没有安装Chrome的情况下启动基于硒的独立exe [英] Launching selenium based stand alone exe without chrome installed

查看:50
本文介绍了在没有安装Chrome的情况下启动基于硒的独立exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用Selenium和WebDriver(Chromedriver)的python脚本.完成此脚本后,我使用cx_freeze将我的脚本编译成一个独立的exe文件,可以双击执行该脚本.但是,对于硒,我一直在使用我下载的chromedriver文件,该文件可与我安装到PC上的chrome应用程序一起使用.

我想做或尝试做的是让我的exe文件与chromedriver一起使用,而不要求用户在自己的计算机上安装google chrome.无论如何,我可以将chrome作为软件包包含在同一目录中以解决此问题吗?

我也愿意接受其他想法.

解决方案

您始终可以捆绑脱机安装程序并提示其安装,只需运行可执行文件即可进行安装.(在此处可用)>

注意:您可能需要研究一些许可问题.

否则,请使用 webbrowser.open('https://www.google.com/chrome/browser/') 将其定向到chrome的安装页面.像这样:

  try:selenium.webbrowser('chrome')#或任何命令除了NameOfExceptionWhenNoBrowserHere:#如果要打开网页:导入网络浏览器INSTALL_PAGE ='https://www.google.com/chrome/browser/'打印(您需要安装Google chrome.")打印(INSTALL_PAGE)如果输入('Open'+ INSTALL_PAGE +'?[是/否]').lower().startswith('y'):webbrowser.open(INSTALL_PAGE)#使用默认浏览器#如果您正在运行脱机安装程序导入子流程导入操作系统_file_dir = os.path.dirname(os.path.realpath(__ file__))打印(您需要安装Google chrome.")打印(现在将打开安装程序")#_file_dir是python文件的目录.#如果安装程序在同一目录中,请像这样运行.subprocess.call(os.path.join(_file_dir,'install_chrome.exe')) 

I have created a python script that uses selenium and a webdriver (Chromedriver). After completing this script, I used cx_freeze to compile my script into a stand alone exe file that I can double click to execute the script. However, with selenium, I have been using the chromedriver file I downloaded that works along the chrome application I have installed onto my pc.

What I would like to do, or try to do is have my exe file work with the chromedriver and not require the user to have google chrome installed onto their computer. Is there anyway I can include the chrome as a package in the same directory to get around this or something?

I am also open to other ideas.

解决方案

You can always bundle the offline installer and prompt it to be installed and just run the executable to install it. (Available here)

NOTE: There may be some licensing issues which you may have to look into.

Otherwise, use webbrowser.open('https://www.google.com/chrome/browser/') to direct them to the installation page for chrome. Something like:

try:
    selenium.webbrowser('chrome')  # Or whatever the command is
except NameOfExceptionWhenNoBrowserHere:
    # If you are opening the web page:

    import webbrowser

    INSTALL_PAGE = 'https://www.google.com/chrome/browser/'
    print('You need to have Google chrome installed.')
    print(INSTALL_PAGE)
    if input('Open ' + INSTALL_PAGE + '? [yes/no]').lower().startswith('y'):
        webbrowser.open(INSTALL_PAGE)  # Uses default browser

    # If you are running the offline installer

    import subprocess
    import os

    _file_dir = os.path.dirname(os.path.realpath(__file__))

    print('You need to have Google chrome installed.')
    print('Will now open installer')

    # _file_dir is the directory of the python file.
    # If the installer is in the same directory, run it like this.
    subprocess.call(os.path.join(_file_dir, 'install_chrome.exe'))

这篇关于在没有安装Chrome的情况下启动基于硒的独立exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆