使用 chromedriver & 创建 Python 可执行文件硒
问题描述
我使用 Selenium & 创建了一个小型网络抓取应用程序.chromedriver 用于将内容输出到 excel 文件的项目.不幸的是,我为这个应用程序开发的人并不是最精通技术的人.
所以我的问题是如何与这些人分享这个应用程序?
我查看了 py2exe.org,但它在创建可执行文件时没有考虑到 chromedriver.有没有更好的方法来做到这一点,而这些人不必手动将文件添加到他们的usr/bin"?
解决方案你可以在 pyinstaller 的帮助下做到这一点
a> :以下是适用于 Windows 的解决方案,但 pyinstaller 表示它也可以在 Mac OS 上运行.
步骤是:
- 打开命令提示符
- 转到 cmd 中存在脚本的项目路径
- 键入 pyinstaller Scriptname.spec Scriptname.py(如果屏幕上出现提示,请输入 y/yes)
- 构建将位于项目路径"distScriptname
注意,传递时需要在Scriptname.spec中提供chromedriver的详细信息
spec 文件的示例内容:
# -*- 模式:python -*-block_cipher = 无a = 分析(['Scriptname.py'],pathex=['Pathofproject'],二进制文件=[('C:\Python27\chromedriver.exe', '**.\selenium\webdriver**')],数据=[],隐藏进口=[],钩子路径=[],runtime_hooks=[],排除=[],win_no_prefer_redirects=假,win_private_assemblies=假,密码=块密码)pyz = PYZ(a.pure, a.zipped_data,密码=块密码)exe = EXE(pyz,a.脚本,exclude_binaries=真,name='createEVIPorg_Automation_new',调试=假,条=假,upx=真,控制台=真)科尔=收集(exe,a.二进制文件,a.zip 文件,a.数据,条=假,upx=真,name='**脚本名**')
您需要更新脚本名称、脚本所在的项目路径、spec 文件中 chromedriver 的路径
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"?
解决方案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:
- Open Command prompt
- Goto project path in cmd where script is present
- type pyinstaller Scriptname.spec Scriptname.py (Enter y/yes if prompt on screen)
- The build will be at 'path to project'distScriptname
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
相关文章