Files
2026-01-30 11:28:35 +08:00

87 lines
3.4 KiB
Python

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import pandas as pd
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from datetime import datetime
from selenium.webdriver.chrome.options import Options
from tqdm import tqdm
# 配置 WebDriver
chrom_dirverpath = "D:\ProgramTools\chromedriver-win64\chromedriver.exe"
# chrome_options = Options()
# chrome_options.add_argument("--headless")
service = Service(executable_path=f'{chrom_dirverpath}')
driver = Chrome(service=service)
def open_page(driver, carId):
# 点击首页
WebDriverWait(driver, 30).until(EC.presence_of_element_located(
(By.XPATH, '//*[@id="main"]/div[1]/div[1]/div[1]/div/div[2]/div/div[1]/div/div/span'))).click()
https = f'https://yunxiu.f6car.cn/erp/view/index.html#/macan-view/cardManage/cardEdit/{carId}'
# 打开页面
driver.get(https)
# 模拟点击
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH,
f"//*[@id='app']/div[1]/div/div/div[2]/div[1]/div/div/div[1]/div[4]/div[2]/div[1]/label/span[1]/span"))).click()
time.sleep(2)
WebDriverWait(driver, 3).until(EC.presence_of_element_located(
(By.XPATH, f"//*[@id='app']/div[1]/div/div/div[2]/div[2]/div/button[1]"))).click()
time.sleep(1)
WebDriverWait(driver, 3).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[5]/div/div[3]/button[1]"))).click()
try:
time.sleep(1)
WebDriverWait(driver, 3).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/div[3]/div[1]/div[1]/div/span'))).click()
except:
pass
print(carId, ":成功")
time.sleep(1)
name = "18742526670"
password = 'Zy18742526670'
path = r"C:\Users\Administrator.DESKTOP-7IC2USJ\Downloads\会员卡信息 (5).xlsx"
df = pd.read_excel(path, engine='openpyxl', sheet_name='会员卡详情', dtype='string')
print(df)
if not df.empty:
carIds = df["卡实体id"]
first_time = datetime.now()
driver.get(f"https://m.f6car.cn/?kickout")
# 登录
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()
# 多店模式需要下面一行代码
# WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '//*[@id="app"]/div[2]/div[1]/div[1]/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div[6]/p[1]'))).click()
# print(1)
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[3]/div/div[1]/button"))).click()
WebDriverWait(driver, 3).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="subMain"]/div/div[3]/div[1]/div[1]/div/span[2]'))).click()
for carId in tqdm(carIds):
try:
open_page(driver, carId)
time.sleep(1)
except:
print(f"{carId},无法打印")
driver.close()
second_time = datetime.now()
time = second_time - first_time
print(f"总计耗时{time}")
else:
print("DataFrame为空,无法打印数据。")