# -*- 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 # 获取会员卡基础信息 pkId = '4061359779622808474' # 手动获取 name = '15888265981' password = 'F6123456' zhi = 1 option_chrome = webdriver.ChromeOptions() option_chrome.add_argument('--headless') for hum in range(zhi): # http='https://yunxiu-trial.f6car.cn/member/customer/list?pageSize=5000&pageNo=1' httptx = 'https://yunxiu.f6car.cn' # 初步加载处理 # 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) 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() ''' try: driver.find_element_by_xpath( '//*[@id="app"]/div/div[1]/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div[1]/p[1]').click() except: print('未识别到多门店') ''' 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') # 获取卡项目 num = 0 for i in range(0, h): # 浮点型 try: d1 = datetime.datetime.now() receiveAmount1 = table.cell(num, 0).value # 按行品牌 receiveAmount2 = table.cell(num, 1).value # 按行零件号 receiveAmount3 = table.cell(num, 2).value # 按行自编码 # https='https://yunxiu-trial.f6car.cn/kzf6/member/index.do?page=/view/index.html%23/customer/detail/'+idMember # 进入链接获取json num = num + 1 time.sleep(0.2) input_box = driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div/div/div[2]/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[2]/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[2]/div/div[3]/div/button/i').click()#确定 time.sleep(0.2) try: input1=driver.find_element_by_xpath('/html/body/div/div/div/div/div/div/div[2]/div[1]/div/div/ul/li/span') if input1.text==receiveAmount1: driver.find_element_by_xpath( '/html/body/div/div/div/div/div/div/div/div/div/div/ul/li[1]/span').click() # 选择 time.sleep(0.2) input_box = driver.find_element_by_xpath( '/html/body/div/div/div/div/div/div/div/div/div[2]/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[2]/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[2]/div/div[3]/div/button/i').click() # 确定 time.sleep(0.2) '//*[@id="cloudTable"]/div[1]/div[3]/table/tbody/tr/td[7]/div' input1 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[2]/div') input2 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[3]/div') input3 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[5]/div') input4 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[6]/div') input6 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div/div/table/tbody/tr[1]/td[7]/div') input5 = driver.find_element_by_xpath('//*[@id="cloudTable"]/div[2]/span') d3 = d1 + datetime.timedelta(hours=10) print(num, '@', receiveAmount3, '@', input1.text, '@', input2.text, '@', input3.text, '@', input4.text, '@', input6.text,'@', input5.text) except: print('未识别到品牌字段') '/html/body/div/div/div/div/div[2]/div[3]/div[2]/div[3]/div/button/span/i' driver.find_element_by_xpath( '/html/body/div/div/div/div/div/div/div/div/div/button/span/i').click() # 取消 ''' 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') d3 = d1 + datetime.timedelta(hours=10) print(num, '@', input1.text, '@', input2.text, '@', input3.text, '@', input4.text, '@', input5.text) ''' except: continue