用chromedriver&创建一个Python可执行文件。硒

时间:2018-04-16 08:54:59

标签: python selenium selenium-chromedriver executable

我使用Selenium& amp;创建了一个小型网络抓取应用程序。 chromedriver用于将内容输出到excel文件的项目。不幸的是,我做这个应用程序的人并不是最懂技术的人。

所以我的问题是如何与这些人分享这个应用程序?

我查看了py2exe.org,但是在创建可执行文件时它并没有考虑到chromedriver。任何更好的方法,没有这些人必须手动将文件添加到他们的" usr / bin"?

1 个答案:

答案 0 :(得分:2)

您可以在pyinstaller的帮助下执行此操作:以下是适用于Windows的解决方案,但pyinstaller表示它也能够在Mac OS上运行。

步骤是:

  1. 打开命令提示符
  2. 转到cmd中存在脚本的项目路径
  3. type pyinstaller Scriptname.spec Scriptname.py(如果屏幕上有提示,请输入y / yes)
  4. 构建将位于'项目路径'\ dist \ Scriptname
  5. 请注意,在传递

    时,您需要在Scriptname.spec中提供chromedriver的详细信息

    spec文件的示例内容:

    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(['Scriptname.py'],
                 pathex=['Pathofproject'],
                 binaries=[('C:\\Python27\\chromedriver.exe', '**.\\selenium\\webdriver**')],
                 datas=[],
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              exclude_binaries=True,
              name='createEVIPOrg_Automation_new',
              debug=False,
              strip=False,
              upx=True,
              console=True )
    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   name='**scriptname**')
    

    您需要更新脚本名称,脚本所在的项目路径,规范文件中的chromedriver路径