吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1396|回复: 9
收起左侧

[求助] python selenium打包后出错的问题

[复制链接]
zhang23588 发表于 2022-3-17 21:11
刚开始学习selenium,在pycharm中运行正常,使用pyinstaller -F 打包后提示出错。错误代码如下
请教问题出在哪?我看说是路径出错了。但是不太明白为什么会这样。
Traceback (most recent call last):
  File "selenium\webdriver\common\service.py", line 71, in start
  File "subprocess.py", line 854, in __init__
  File "subprocess.py", line 1307, in _execute_child
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sh1.4.py", line 7, in <module>
  File "selenium\webdriver\chrome\webdriver.py", line 70, in __init__
  File "selenium\webdriver\chromium\webdriver.py", line 90, in __init__
  File "selenium\webdriver\common\service.py", line 81, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

[10996] Failed to execute script 'sh1.4' due to unhandled exception!




这个是python的代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = Options()
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(options=chrome_options)
driver.get("http://youtonwangluo.cn/#/login?redirect=%2FbillDetail%2FbillDetail_examine")
print('开始打开网页')
driver.find_element("name", "username").send_keys("0000002")

driver.find_element("name", "password").send_keys("123456")
print('登录成功')
driver.find_element("class name", "el-button--primary").click()

time.sleep(5)
driver.find_element("class name", "el-icon-search").click()  # 查找开始
print('开始更新数据')

try:
    n = 10
    for i in range(10):
        time.sleep(5)
        driver.find_element("class name", "el-checkbox__inner").click()
        time.sleep(1)
        driver.find_element("class name", "el-icon-s-help").click()
        time.sleep(1)
        driver.find_element("class name", "el-button--primary").click()
        print(n, "条数据已审核")
        n = n + 10

except:
    driver.close()
    print("自动审核已完成")

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

xhtdtk 发表于 2022-3-17 21:22
Message: 'chromedriver' executable needs to be in PATH
我猜测打包没问题,应该是没把浏览器驱动和打包好的exe文件放在一起
唯爱丶雪 发表于 2022-3-17 21:34
我之前打包过的,没问题的,不需要浏览器驱动放一起打包,直接打包的py脚本
xhtdtk 发表于 2022-3-17 21:37
唯爱丶雪 发表于 2022-3-17 21:34
我之前打包过的,没问题的,不需要浏览器驱动放一起打包,直接打包的py脚本

但是打包好要把浏览器驱动放一起
driver = webdriver.Chrome(options=chrome_options)
说明浏览器驱动默认路径和程序路径是一样的
 楼主| zhang23588 发表于 2022-3-17 22:04
xhtdtk 发表于 2022-3-17 21:37
但是打包好要把浏览器驱动放一起
driver = webdriver.Chrome(options=chrome_options)
说明浏览器驱动 ...

问题解决。需要把驱动放到一起才能使用。
ccwuax 发表于 2022-3-17 22:55
不放在一起也没关系,但你要指定驱动的路径,不然就会像你这样找不到
iwatermelon 发表于 2022-3-17 23:20
不错,学习了。
马了顶大 发表于 2022-3-17 23:43
看错误提示: Message: 'chromedriver' executable needs to be in PATH.
需要为chromedriver配置环境变量或者在代码中设置驱动路径,如果是默认的话就需要把驱动和打包后的程序放在一起
 楼主| zhang23588 发表于 2022-3-18 11:15
马了顶大 发表于 2022-3-17 23:43
看错误提示: Message: 'chromedriver' executable needs to be in PATH.
需要为chromedriver配置环境变量 ...

明白了。谢谢  
SoftwareTesting 发表于 2022-3-18 17:23
环境变量吧
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-6-11 03:22

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表