Files
F6--/F6系统常用脚本/数据清洗材料属性(品牌+零件号).py
T
2026-01-30 11:28:35 +08:00

120 lines
5.9 KiB
Python

# -*- coding:UTF-8 -*-
# 功能:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
import time
import xlrd
import xlwt
import re
import datetime
from xlutils.copy import copy
from selenium.webdriver.common.keys import Keys
from shutil import which
# 输入基础信息
name = '15888265981'
password = 'F6123456'
cycles = 1
option_chrome = webdriver.ChromeOptions()
option_chrome.add_argument('--headless')
for hum in range(cycles):
# 初步加载处理
# chrom_opt = webdriver.ChromeOptions()
# prefs = { "profile.managed_default_content_settings.images": 2 }
# chrom_opt.add_experimental_option("prefs", prefs)
# driver = webdriver.Chrome(executable_path="E:/Python/chromedriver.exe", chrome_options=chrom_opt)
# 无显示预处理
# option=webdriver.ChromeOptions()
# option.add_argument('headless') # 设置option
# driver = webdriver.Chrome(chrome_options=option)
# 进入链接获取json
# driver = webdriver.Chrome(chrome_options=option_chrome)
driver = webdriver.Chrome(executable_path=r"C:\迅雷下载\python 暂存文件\Python\chromedriver.exe")
driver.maximize_window()
driver.implicitly_wait(0.2)
httptx = 'https://yunxiu.f6car.cn'
driver.get(httptx)
driver.find_element_by_xpath('//*[@id="pane-username"]/form/div[1]/div/div/input').send_keys(name)
driver.find_element_by_xpath('//*[@id="pane-username"]/form/div[2]/div/div[1]/input').send_keys(password)
driver.find_element_by_xpath('//*[@id="pane-username"]/form/div[3]/div/button/span').click()
time.sleep(10) # 预设时间
print("登陆系统")
print("创建文件")
# 新建一个excel文件
file = xlwt.Workbook() # 注意这里的Workbook首字母是大写,无语吧
# 新建sheet
table = file.add_sheet('sheet name', cell_overwrite_ok=True)
# 打开excel文件
print("打开文件")
data = xlrd.open_workbook(r'C:\Users\admin\Desktop\Python脚本\图形界面自动化脚本\F6系统常用脚本\Excel通用存储位置.xls')
print(data)
table = data.sheet_by_index(0) # 通过索引顺序获取
h = table.nrows
https = 'https://yunxiu.f6car.cn/kzf6/partInfo/newPageList.do?page=view%2Fmaterial.html%23/info/list/cloud'
driver.get(https)
# 传值转换
#driver.switch_to.frame('weixin-page-iframe')
# 获取信息
for i in range(1, h):
try:
d1 = datetime.datetime.now()
receiveAmount1 = table.cell(i, 0).value # 按行品牌
receiveAmount2 = table.cell(i, 1).value # 按行零件号
receiveAmount3 = table.cell(i, 2).value # 按行自编码
receiveAmount4 = "空值 " # 预设一个值
try:
receiveAmount5 = driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div[3]/div/button/span') # 获取一个品牌信息
receiveAmount4 = receiveAmount5.text
except:
cycles = 1
if receiveAmount1 != receiveAmount4: # 不相等则说明 需要重新选择品牌
# 判断之前是否有筛选品牌
try:
driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div[3]/div/button/span/i').click()
except:
cycles = 1
# 输入品牌进行筛选
time.sleep(0.2)
input_box = driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/input')
input_box.send_keys(Keys.CONTROL, 'a')
input_box.send_keys(Keys.BACK_SPACE)
# input_box.send_keys(Keys.CONTROL, 'v')
driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/input').send_keys(
receiveAmount1)
time.sleep(0.2)
driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/div/button/i').click()
time.sleep(0.2)
try:
input0=driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div/div/div/ul/li/span')
if input0.text==receiveAmount1:
driver.find_element_by_xpath(
'/html/body/div/div/div/div/div/div/div/div/div/div/ul/li[1]/span').click()
except:
cycles = 1
# 输入零件号进行查询并记录内容
try:
time.sleep(0.2)
input_box = driver.find_element_by_xpath(
'/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/input')
input_box.send_keys(Keys.CONTROL, 'a')
input_box.send_keys(Keys.BACK_SPACE)
# input_box.send_keys(Keys.CONTROL, 'v')
driver.find_element_by_xpath(
'/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/input').send_keys(receiveAmount2)
time.sleep(0.2)
driver.find_element_by_xpath(
'/html/body/div/div/div/div/div/div/div/div/div/div/div[3]/div/button/i').click() # 确定
time.sleep(0.2)
input1 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[1]/div')
input2 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[2]/div')
input3 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[4]/div')
input4 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[6]/div')
input5 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div[2]/span')
print(i, '@', receiveAmount3, '@', input1.text, '@', input2.text, '@', input3.text, '@', input4.text, '@', input5.text, '@',d1)
except:
print(i,d1)
except:
continue