Create a Python executable with chromedriver amp; Selenium(使用 chromedriver amp; 创建 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
这篇关于使用 chromedriver & 创建 Python 可执行文件硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 chromedriver & 创建 Python 可执行文件硒
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
