98 lines
4.2 KiB
Python
98 lines
4.2 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
|
|
from xlutils.copy import copy
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
import datetime
|
|
import os
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support.wait import WebDriverWait
|
|
import pandas as pd
|
|
#获取基础信息
|
|
name = '15888265981'
|
|
password = 'F6123456'
|
|
option_chrome = webdriver.ChromeOptions()
|
|
option_chrome.add_argument('--headless')
|
|
|
|
http='https://m.f6car.cn/'
|
|
#driver = webdriver.Chrome(chrome_options=option_chrome)
|
|
driver = webdriver.Chrome(executable_path=r"C:\迅雷下载\python 暂存文件\Python\chromedriver.exe")
|
|
driver.maximize_window()
|
|
driver.implicitly_wait(2)
|
|
driver.get(http)
|
|
|
|
# 在输入框中输入账号和密码
|
|
username = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id="pane-username"]/form/div[1]/div/div[1]/input')))
|
|
enter = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id="pane-username"]/form/div[3]/div/button')))
|
|
username.clear()
|
|
username.send_keys(name)
|
|
driver.find_element_by_xpath(r'//*[@id="pane-username"]/form/div[2]/div/div[1]/input').send_keys(password)
|
|
enter.click()
|
|
time.sleep(15)#预设时间
|
|
|
|
file = xlwt.Workbook()
|
|
table = file.add_sheet('sheet name', cell_overwrite_ok=True)
|
|
#打开excel文件
|
|
data = xlrd.open_workbook(r"C:\Users\admin\Desktop\Python脚本\图形界面自动化脚本\F6系统常用脚本\Excel通用存储位置.xls")
|
|
print(data)
|
|
table = data.sheet_by_index(0) # 通过索引顺序获取
|
|
h = table.nrows
|
|
l = table.ncols
|
|
print(u"表数据的行数为%s,列数为%s"%(h,l))
|
|
|
|
for i in range(1,h):
|
|
try:
|
|
idMember =table.cell(i, 0).value #id
|
|
idMember1 =table.cell(i, 1).value #日期
|
|
httpas='https://yunxiu.f6car.cn/cayenne/view/index.html#/cayenne-promotion/marketing/vipList'
|
|
driver.get(httpas)
|
|
time.sleep(0.5)
|
|
try:
|
|
driver.find_element_by_xpath('/html/body/div/div/div[3]/button[1]').click()
|
|
time.sleep(0.5)
|
|
except:
|
|
a = 1
|
|
https='https://yunxiu.f6car.cn/cayenne/view/index.html#/cayenne-promotion/marketing/cardEdit/'+idMember #进入页面
|
|
driver.get(https)
|
|
time.sleep(0.5)
|
|
#传值转换
|
|
#driver.switch_to.frame('weixin-page-iframe')
|
|
driver.find_element_by_xpath(
|
|
'//*[@id="app"]/div[2]/div[2]/div/div[2]/div/form/div[1]/div/div/div/div/div[2]/label/span[1]/span').click() #点击永久
|
|
time.sleep(0.5)
|
|
#荣大
|
|
#time.sleep(0.1)
|
|
# 先通过日期输入框的id="train_date"来定位输入框,再通过removeAttribute方法移除"readonly"属性
|
|
#js = 'document.getElementById("train_date").removeAttribute("readonly");'
|
|
#ele = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div/div[2]/div[6]/form/div[1]/div[4]/div/div/div/div[1]/div/input')
|
|
#driver.execute_script("arguments[0].removeAttribute('readonly');", ele)
|
|
# js = """
|
|
# var date = document.getElementById('train_date').removeAttribute('readonly');
|
|
# """
|
|
|
|
# driver.execute_script(js)
|
|
#ele.click() # 先点击,清空后赋值。
|
|
#ele.clear()
|
|
#time.sleep(0.2)
|
|
driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div/div[2]/div[6]/form/div[1]/div[4]/div/div/div/div[1]/div/input').send_keys(idMember1)
|
|
time.sleep(0.5)
|
|
driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[2]/div/div[2]/div[6]/form/div[1]/div[3]/div/div/div/div[1]/div/input').click()
|
|
time.sleep(0.5)
|
|
driver.find_element_by_xpath('/html/body/div/div/div[3]/button[1]').click()
|
|
time.sleep(0.5)
|
|
driver.find_element_by_xpath(
|
|
'//*[@id="app"]/div[2]/div[2]/div/div[3]/button[1]').click() #点击保存
|
|
time.sleep(0.5)
|
|
endtime = datetime.datetime.now()
|
|
print(i,'@', idMember)
|
|
except:
|
|
print('失败')
|
|
continue |