135 lines
6.0 KiB
Plaintext
135 lines
6.0 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 6,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 导入库\n",
|
||
"import os\n",
|
||
"from selenium import webdriver\n",
|
||
"from selenium.webdriver.common.keys import Keys\n",
|
||
"from selenium.webdriver.support import expected_conditions as EC\n",
|
||
"from selenium.webdriver.common.by import By\n",
|
||
"from selenium.webdriver.support.wait import WebDriverWait\n",
|
||
"import time\n",
|
||
"import pandas as pd\n",
|
||
"import numpy as np\n",
|
||
"import requests\n",
|
||
"import json\n",
|
||
"import time\n",
|
||
"import re\n",
|
||
"from datetime import datetime\n",
|
||
"from dateutil.relativedelta import relativedelta\n",
|
||
"from pathlib import Path\n",
|
||
"from urllib.parse import quote\n",
|
||
"from io import BytesIO\n",
|
||
"from selenium.webdriver.common.action_chains import ActionChains\n",
|
||
"from selenium.webdriver import ChromeOptions\n",
|
||
"from selenium import webdriver\n",
|
||
"# 账号密码 -- 需要修改\n",
|
||
"name = '17710217084'\n",
|
||
"password = '123456Zy~'\n",
|
||
"\n",
|
||
"driver = webdriver.Chrome(executable_path=r\"C:\\Users\\admin\\Desktop\\Python脚本\\chromedriver.exe\")\n",
|
||
"\n",
|
||
"\n",
|
||
"real_https = 'https://fws.carzone365.com/#/store/quitAudit' # 正式网址\n",
|
||
"# 打开网页,根据情况更改网址变量\n",
|
||
"driver.get(real_https)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 开始批量导入\n",
|
||
"\n",
|
||
"try:\n",
|
||
" # 找到按钮里的 input 标签\n",
|
||
" to_input = driver.find_element_by_xpath(r'//*[@id=\"app\"]/div/div/div/div[2]/form/div[1]/div/div/div/div[1]/input')\n",
|
||
" time.sleep(0.2)\n",
|
||
" upload_file = os.path.join(files_path,file)\n",
|
||
" to_input.send_keys(upload_file)\n",
|
||
" time.sleep(1)\n",
|
||
" print(f'已经上传excel文件:{file}!')\n",
|
||
" # 点击 立即导入按钮\n",
|
||
" WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[2]/form/div[1]/div/button/span'))).click()\n",
|
||
" # 刷新页面\n",
|
||
" time.sleep(5)\n",
|
||
" driver.refresh()\n",
|
||
" # 点击 查看导入记录 按钮\n",
|
||
" WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[2]/form/div[2]/div/div[1]'))).click()\n",
|
||
" # 检查文件名\n",
|
||
" upload_file_name = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, r' //*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[1]/div'))).text\n",
|
||
" time.sleep(0.5)\n",
|
||
" while upload_file_name != file:\n",
|
||
" # 关闭再打开 导入记录\n",
|
||
" WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[1]/button/i'))).click() # 关闭按钮\n",
|
||
" time.sleep(1)\n",
|
||
" WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[2]/form/div[2]/div/div[1]'))).click() \n",
|
||
" time.sleep(1)\n",
|
||
" upload_file_name = WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH, r' //*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[1]/div'))).text\n",
|
||
"\n",
|
||
" print('导入文件已经进入导入记录中!')\n",
|
||
"\n",
|
||
" # 打印卡导入 状态 信息\n",
|
||
" succeed_cards = driver.find_element_by_xpath(r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[3]/div').text \n",
|
||
" time.sleep(0.5)\n",
|
||
" lost_cards = driver.find_element_by_xpath(r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[4]/div').text \n",
|
||
" time.sleep(0.5)\n",
|
||
" print(f'成功卡数:{succeed_cards},失败卡数:{lost_cards}')\n",
|
||
" while succeed_cards == '' or lost_cards == '':\n",
|
||
" # 不断的关闭打开 导入记录 ,刷新页面\n",
|
||
" WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[1]/button/i'))).click() # 关闭按钮\n",
|
||
" time.sleep(1)\n",
|
||
" WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[2]/form/div[2]/div/div[1]'))).click() # 导入记录\n",
|
||
" time.sleep(1)\n",
|
||
" succeed_cards = driver.find_element_by_xpath(r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[3]/div').text \n",
|
||
" time.sleep(1)\n",
|
||
" lost_cards = driver.find_element_by_xpath(r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[4]/div').text \n",
|
||
" time.sleep(10)\n",
|
||
" print(f'succeed_cards:{succeed_cards},lost_cards:{lost_cards}',end='-')\n",
|
||
"\n",
|
||
" print('#######################可以导入下一个文件!#######################')\n",
|
||
" # 关闭 导入记录 窗口\n",
|
||
" WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, r'//*[@id=\"app\"]/div/div/div/div[3]/div/div[1]/button/i'))).click()\n",
|
||
"except Exception as e :\n",
|
||
" print(f'出错')\n",
|
||
"finally:\n",
|
||
" time.sleep(10) # 如果时间足够的话,保险起见可以多等一会"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3.9.4 ('F6processing')",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.9.4"
|
||
},
|
||
"orig_nbformat": 4,
|
||
"vscode": {
|
||
"interpreter": {
|
||
"hash": "f83923c7d0b4d2e003073efbd633777fa3fd66b7578149f24f67f4796b9b3ac4"
|
||
}
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|