Create a Python executable with chromedriver & Selenium

若如初见. 提交于 2019-12-05 06:22:02

问题


I have created a small web scraping app using Selenium & chromedriver for a project that outputs the content into an excel file. The people I did this app for unfortunately aren't the most tech-savvy.

So my question is how can I share this app with these people?

I looked into py2exe.org, but it doesn't take the chromedriver into account when creating the executable. Any better ways of doing this, without these people having to add the files manually to their "usr/bin"?


回答1:


You can do this with the help of pyinstaller : Below is the solution which work on Windows but pyinstaller says its capable of working on Mac OS also.

Steps are:

  1. Open Command prompt
  2. Goto project path in cmd where script is present
  3. type pyinstaller Scriptname.spec Scriptname.py (Enter y/yes if prompt on screen)
  4. The build will be at 'path to project'\dist\Scriptname

Note you need to provide the details of chromedriver in Scriptname.spec when passing the

Sample content of spec file:

# -*- 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**')

You need to update the Scriptname, project path where you script lies, path of chromedriver in spec file



来源:https://stackoverflow.com/questions/49853252/create-a-python-executable-with-chromedriver-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!