问题描述
本机上调试顺利运行的代码生成exe打包文件后.。在另一台电脑上运行提示[WinError 2] 系统找不到指定文件
脚本代码
import sys
import time
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains # 鼠标操作的方法
from openpyxl import load_workbook
from openpyxl.styles import PatternFill
import win32api
import win32api
import win32con
import os
import shutil
# 浏览器初始化
d = webdriver.Chrome()
d.get('http://xxxx.jsp')
# 单开浏览器调试
# chrome_options = Options()
# chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:xxxx")
# d = webdriver.Chrome(options=chrome_options)
print("请在30s内输入密码并且登入,页面加载完成后点击随便点表格一行,之后不要碰鼠标键盘了,直至完成")
time.sleep(30)
# 发送三次空格,加载页面元素
win32api.keybd_event(32,0,0,0)
win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(32,0,0,0)
win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(32,0,0,0)
win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(2)
#加载文件
wb = load_workbook('./xxx统计表.xlsx')
sheet_names = wb.sheetnames # 返回一个列表
ws = wb[sheet_names[0]] # index为0为第一张表
search_fushu = d.find_element(By.XPATH, '//div[@title="xxx团委"]')
ActionChains(d).double_click(search_fushu).perform()
print("等到页面加载中...")
time.sleep(3.5)
fushu_cow = d.find_elements(By.XPATH,'//div[@title="xxx总支"]/../../../../tr/td[3]/div/div')
j = 3
i = 1
while(i < 13):
print(fushu_cow[i].text,end = " ") # 输出网页表格的数据
while(j < 15):
cell = ws.cell(row=j,column=2)
cell.value = int(fushu_cow[i].text)
j = j + 1
break
i = i + 1
wb.save('xxx统计表_2.xlsx')
close = d.find_element(By.CSS_SELECTOR,'[class="dw-res-wnd-header-closebtn"]')
ActionChains(d).double_click(close).perform()
print("xxx统计表 导出成功...")
time.sleep(0.5)
wb = load_workbook('./xxx统计表.xlsx')
sheet_names = wb.sheetnames # 返回一个列表
ws = wb[sheet_names[0]] # index为0为第一张表
search_fushu = d.find_element(By.XPATH, '//div[@title="xxx团委"]')
ActionChains(d).double_click(search_fushu).perform()
print("等到页面加载中...")
time.sleep(3.5)
xinxue_cow = d.find_elements(By.XPATH,'//div[@title="xxx-本级"]/../../../../tr/td[3]/div/div')
j = 3
i = 1
while(i < 5):
print(xinxue_cow[i].text,end = " ") # 输出网页表格的数据
while(j < 7):
cell = ws.cell(row=j,column=2)
cell.value = int(xinxue_cow[i].text)
j = j + 1
break
i = i + 1
wb.save('xxx统计表_2.xlsx')
close = d.find_element(By.CSS_SELECTOR,'[class="dw-res-wnd-header-closebtn"]')
ActionChains(d).double_click(close).perform()
print("xxx导出成功...")
time.sleep(0.5)
search_chaxun= d.find_element(By.XPATH, '//a[@class="dw-textButton-text"][@title="查询"]')
ActionChains(d).click(search_chaxun).perform()
time.sleep(3)
wb = load_workbook('./xxx统计表.xlsx')
sheet_names = wb.sheetnames # 返回一个列表
ws = wb[sheet_names[0]] # index为0为第一张表
j = 3
while(j < 18):
cell = ws.cell(row=j,column=1) # 获取单位名称
if 10 < j < 18:
fill = PatternFill(start_color ='FFFFFF', end_color = 'FFFFFF', fill_type = 'solid') #填充白色
ws.cell(row=j,column=1).fill = fill
title = cell.value
path = '//div[@title="' + title + '"]/../../following-sibling::*/div/div'
search_cow = d.find_element(By.XPATH, path)
print(int(search_cow.text)) # 打印获取大的网页表格数据
count = ws.cell(row=j,column=3)
count.value = int(search_cow.text)
j = j + 1
ws.move_range("A18:E18", rows=1)
wb.save('xxx统计表_2.xlsx')
print("xxx统计表 导出成功...")
########################################################批量下载######################################################################
print("开始批量下载ing...")
wb = load_workbook('./xxx统计表.xlsx')
sheet_names = wb.sheetnames # 返回一个列表
ws = wb[sheet_names[0]] # index为0为第一张表
j = 3
while(j < 18):
cell = ws.cell(row=j,column=1) # 获取单位名称
title = cell.value
path = '//div[@title="' + title + '"]' # 生成路径
search_cow = d.find_element(By.XPATH, path)
ActionChains(d).double_click(search_cow).perform()
time.sleep(3)
find = d.find_elements(By.XPATH,'//a[@class="dw-textButton-text"][@title="导出xx记录"]')
ActionChains(d).click(find[1]).perform()
time.sleep(1)
win32api.keybd_event(13,0,0,0)
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(1)
close = d.find_element(By.CSS_SELECTOR,'[class="dw-res-wnd-header-closebtn"]') # 关闭弹出的窗口
ActionChains(d).click(close).perform()
num = 17
#设置倒计时时间
print("\r正在加载:" + "|" + "*" * j + " "*(num+1-j)+"|" + str(int(j/num*100))+"%", end="\r",flush=True)
time.sleep(0.5)
j = j + 1
print("下载完毕。。分类中。。。")
# cur_path = '../..'
# shutil.move('../../xxx.xls', '../../xx')
# shutil.move('../../xxx.xls', '../../xxx')
# files = os.listdir(cur_path)
# for f in files:
# if f.split('.')[-1] == "xls":
# shutil.move(cur_path + '/' + f, cur_path + '/医学部/医学部青年大学习学习名单')
print("运行完毕,请检查!")
print("5s后自动关闭此窗口")
time.sleep(5)
os.system("taskkill /f /im cmd.exe") # 关闭cmd窗口
运行结果及报错内容
因为一闪而过,所以拍的视频,是管理员模式启动的exe
我的解答思路和尝试过的方法
另一台电脑是没装python的,我看到是因为却了selenium的东西,我就直接在另一台电脑装了个py和本脚本用到的所有库,还是不行,报错一样
我想要达到的结果
可以顺畅的运行
代码有优化的地方还请各位指正