Files
F6--/张阳脚本/竞品系统数据导出/大大汽修点击导出(1).ipynb
2026-01-30 11:28:35 +08:00

449 lines
27 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 客户车辆信息导出"
]
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-07-08T01:22:38.302541Z",
"start_time": "2025-07-08T01:21:21.261993Z"
}
},
"source": [
"from selenium import webdriver\n",
"from selenium.webdriver.support.ui import Select\n",
"from selenium.webdriver import ActionChains\n",
"import time\n",
"import xlrd\n",
"import xlwt\n",
"import re\n",
"import datetime\n",
"from xlutils.copy import copy\n",
"from selenium.webdriver.common.keys import Keys\n",
"from selenium.webdriver.common.action_chains import ActionChains\n",
"from selenium.webdriver.common.by import By\n",
"import pandas as pd\n",
"\n",
"# 登录\n",
"name = '13568162018'\n",
"password = 'a123456'\n",
"option_chrome = webdriver.ChromeOptions()\n",
"option_chrome.add_argument('--headless')\n",
"http='https://qixiu.dada365.com/login'\n",
"from selenium import webdriver\n",
"from selenium.webdriver.chrome.service import Service\n",
"\n",
"# 如果 ChromeDriver 已经添加到系统的 PATH 中,可以这样写:\n",
"service = Service()\n",
"\n",
"# 如果 ChromeDriver 没有在 PATH 中,则需要指定其路径:\n",
"service = Service(executable_path=r\"D:\\ProgramTools\\chromedriver-win64\\chromedriver.exe\")\n",
"\n",
"# 创建一个新的 Chrome 浏览器实例\n",
"driver = webdriver.Chrome(service=service)\n",
"\n",
"# 打开大大汽修平台登录页面\n",
"driver.get(http)\n",
"# driver = webdriver.Chrome(executable_path=r\"D:\\ProgramTools\\chromedriver-win64\\chromedriver.exe\")\n",
"driver.maximize_window()\n",
"driver.implicitly_wait(1)\n",
"driver.get(http)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[1]/div/div/input').send_keys(name)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[2]/div/div/input').send_keys(password)\n",
"time.sleep(3)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[4]/div/button/span').click()\n",
"time.sleep(3)\n",
"# 点击车辆管理\n",
"\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[1]/div[1]/ul/div/div[3]/li/div/span').click()\n",
"# driver.find_element(By.XPATH,'(//div[@id=\"app\"]//ul/div[1]/div[3])[1]').click()\n",
"time.sleep(2)\n",
"# 点击车辆查询\n",
"driver.find_element(By.XPATH,'/html/body/div[2]/ul/li[1]/span').click()\n",
"time.sleep(3)\n",
"# 点击500条每页\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[2]/div[3]/div/span[2]/div/div/span/span/i').click()\n",
"\n",
"time.sleep(3)\n",
"driver.find_element(By.XPATH,'/html/body/div[3]/div[1]/div[1]/ul/li[6]/span').click()\n",
"\n",
"# 点击查看\n",
"time.sleep(10)\n",
"# for a in range(1,3):\n",
"for i in range(1,501):\n",
" try:\n",
" driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[2]/div[2]/div/div[2]/div[3]/table/tbody/tr[%s]/td[13]/div/button[1]/span'%i).click()\n",
" time.sleep(2)\n",
" car_no=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/span[1]') \n",
" name=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/span[2]')\n",
" print(2)\n",
"\n",
" phone_num=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[1]/li[1]')\n",
" print(3) \n",
" identity_num=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[1]/li[2]')\n",
" print(4)\n",
" insur_com=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[1]/li[3]')\n",
" print(5)\n",
" \n",
" insur_date=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[1]/li[4]')\n",
"\n",
" vin_num=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[2]/li[1]')\n",
" print(6)\n",
" car_modle=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[2]/li[2]/strong/span')\n",
" print(7)\n",
" engin_num=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[2]/li[3]')\n",
" car_date=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[2]/li[4]')\n",
" memo=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/div[4]/ul[5]/li/span[2]')\n",
" print(8)\n",
" print(car_no.text,\"@\",name.text,\"@\",phone_num.text,\"@\",identity_num.text,\"@\",insur_com.text,\"@\",vin_num.text,\"@\",car_modle.text,\"@\", memo.text)\n",
" driver.find_element(By.XPATH,'//*[@id=\"tab-item-2\"]/span[2]').click()\n",
" except:\n",
" print(\"有误\")\n",
" driver.find_element(By.XPATH,'//*[@id=\"tab-item-2\"]/span[2]').click()\n",
" # driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[2]/div[3]/div/ul/li[%s]'%a).click()\n",
" "
],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SX3667 @ 何 @ 车主电话: 13982846671 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: JF1GP25C2DG065475 @ 斯巴鲁 XV XV 2.0 2012年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S339X6 @ 李 @ 车主电话: 18582830888 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LSVAK2185B2333118 @ 大众 朗逸 朗逸 1.6 2011年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SEZ717 @ 周欣 @ 车主电话: 15882942902 @ 身份证号码: 513001199312051019 @ 保险公司: 暂无 @ 车架号: LC0CG4DF7G0013987 @ 比亚迪 元 元 1.5 2016年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S250K0 @ 李 @ 车主电话: 15281866877 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LVSHFCAC5MS221747 @ 福特 锐际 锐际 2.0 2020年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SFT881 @ 唐艳 @ 车主电话: 15390125925 @ 身份证号码: 513023197405246746 @ 保险公司: 暂无 @ 车架号: LSVX065N9E2159128 @ 大众 途观 途观 1.8 2015年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SWZ316 @ 13982824053 @ 车主电话: 18780800015 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LHGCV1641L9001579 @ 本田 雅阁 第十代雅阁 1.5 2018年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S09F2T @ 袁远 @ 车主电话: 18481969666 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: WBA8X3103JBM92377 @ 宝马 3 Series [3系] GT 320i 2.0 2018年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川Y63V90 @ 阳 @ 车主电话: 18282745485 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LSVDU2BM6KN101225 @ 大众 凌渡 凌渡 1.4 2019年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S158V9 @ 魏 @ 车主电话: 15882940035 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LS4ASB2E7FA702842 @ 长安商用 欧诺 欧诺 1.5 2012年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SQ226F @ 雷亚军 @ 车主电话: 13547247727 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LZWDAAGA1C7215513 @ 五菱 荣光 荣光小卡 1.2 2010年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S97Q07 @ 卢姐 @ 车主电话: 13808241818 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: W1KUG5GB6LA533010 @ 奔驰 S-Class [S级] S 350 L 48V 3.0 2020年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S90E91 @ 杨 @ 车主电话: 13228276199 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LFPM4APE0J1A23984 @ 马自达 CX-4 CX-4 2.0 2018年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SYJ559 @ 李 @ 车主电话: 17760078550 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LGBM4AE44MS462782 @ 日产 奇骏 奇骏 2.0 2021年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S1D278 @ 罗 @ 车主电话: 13882895869 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LGWDBE194MB010263 @ 长城 风骏 风骏5 2.0 2021年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SEH608 @ 张 @ 车主电话: 15775628388 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LSV7N60T7M2026048 @ 大众 途观 途观L R-Line 2.0 2021年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"渝AFV6238 @ 王 @ 车主电话: 19160657666 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LB378LCZ3PB132953 @ 银河 L7 L7 1.5 2023年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川S8U220 @ 李 @ 车主电话: 18982881545 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LS5A3DEE9KA422866 @ 长安 CS55 CS55 1.5 2019年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川SD99133 @ 卢 @ 车主电话: 15228099005 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: LJ1E6A2UXRG009850 @ 蔚来 ES6 ES6 电动 2023年款 @ 暂无\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"川G8HE47 @ 孙 @ 车主电话: 18398080313 @ 身份证号码: 暂无 @ 保险公司: 暂无 @ 车架号: W0LLB6E02DB057005 @ 欧宝 Antara [安德拉] Antara [安德拉] 2.4 2013年款 @ 暂无\n",
"有误\n"
]
},
{
"ename": "InvalidSessionIdException",
"evalue": "Message: invalid session id\nStacktrace:\n\tGetHandleVerifier [0x0x7ff6d1fccda5+78885]\n\tGetHandleVerifier [0x0x7ff6d1fcce00+78976]\n\t(No symbol) [0x0x7ff6d1d899fc]\n\t(No symbol) [0x0x7ff6d1dd07df]\n\t(No symbol) [0x0x7ff6d1e08a52]\n\t(No symbol) [0x0x7ff6d1e03413]\n\t(No symbol) [0x0x7ff6d1e024d9]\n\t(No symbol) [0x0x7ff6d1d55d55]\n\tGetHandleVerifier [0x0x7ff6d22a4eed+3061101]\n\tGetHandleVerifier [0x0x7ff6d229f33d+3037629]\n\tGetHandleVerifier [0x0x7ff6d22be592+3165202]\n\tGetHandleVerifier [0x0x7ff6d1fe730e+186766]\n\tGetHandleVerifier [0x0x7ff6d1feeb3f+217535]\n\t(No symbol) [0x0x7ff6d1d54dca]\n\tGetHandleVerifier [0x0x7ff6d23c45e8+4238440]\n\tBaseThreadInitThunk [0x0x7ffa253de8d7+23]\n\tRtlUserThreadStart [0x0x7ffa25ddc34c+44]\n",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mInvalidSessionIdException\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[6], line 65\u001B[0m\n\u001B[0;32m 64\u001B[0m time\u001B[38;5;241m.\u001B[39msleep(\u001B[38;5;241m2\u001B[39m)\n\u001B[1;32m---> 65\u001B[0m car_no\u001B[38;5;241m=\u001B[39mdriver\u001B[38;5;241m.\u001B[39mfind_element(By\u001B[38;5;241m.\u001B[39mXPATH,\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m//*[@id=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mapp\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m]/div/div[2]/div[2]/div[3]/div[1]/span[1]\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[0;32m 66\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;241m1\u001B[39m) \n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:748\u001B[0m, in \u001B[0;36mWebDriver.find_element\u001B[1;34m(self, by, value)\u001B[0m\n\u001B[0;32m 746\u001B[0m value \u001B[38;5;241m=\u001B[39m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m[name=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mvalue\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m]\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[1;32m--> 748\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mexecute(Command\u001B[38;5;241m.\u001B[39mFIND_ELEMENT, {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124musing\u001B[39m\u001B[38;5;124m\"\u001B[39m: by, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m: value})[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:354\u001B[0m, in \u001B[0;36mWebDriver.execute\u001B[1;34m(self, driver_command, params)\u001B[0m\n\u001B[0;32m 353\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response:\n\u001B[1;32m--> 354\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39merror_handler\u001B[38;5;241m.\u001B[39mcheck_response(response)\n\u001B[0;32m 355\u001B[0m response[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_unwrap_value(response\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m))\n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py:229\u001B[0m, in \u001B[0;36mErrorHandler.check_response\u001B[1;34m(self, response)\u001B[0m\n\u001B[0;32m 228\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m exception_class(message, screen, stacktrace, alert_text) \u001B[38;5;66;03m# type: ignore[call-arg] # mypy is not smart enough here\u001B[39;00m\n\u001B[1;32m--> 229\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m exception_class(message, screen, stacktrace)\n",
"\u001B[1;31mInvalidSessionIdException\u001B[0m: Message: invalid session id: session deleted as the browser has closed the connection\nfrom disconnected: not connected to DevTools\n (Session info: chrome=138.0.7204.97)\nStacktrace:\n\tGetHandleVerifier [0x0x7ff6d1fccda5+78885]\n\tGetHandleVerifier [0x0x7ff6d1fcce00+78976]\n\t(No symbol) [0x0x7ff6d1d89bca]\n\t(No symbol) [0x0x7ff6d1d759b5]\n\t(No symbol) [0x0x7ff6d1d9a9ca]\n\t(No symbol) [0x0x7ff6d1e105e5]\n\t(No symbol) [0x0x7ff6d1e30b42]\n\t(No symbol) [0x0x7ff6d1e08963]\n\t(No symbol) [0x0x7ff6d1dd16b1]\n\t(No symbol) [0x0x7ff6d1dd2443]\n\tGetHandleVerifier [0x0x7ff6d22a4eed+3061101]\n\tGetHandleVerifier [0x0x7ff6d229f33d+3037629]\n\tGetHandleVerifier [0x0x7ff6d22be592+3165202]\n\tGetHandleVerifier [0x0x7ff6d1fe730e+186766]\n\tGetHandleVerifier [0x0x7ff6d1feeb3f+217535]\n\tGetHandleVerifier [0x0x7ff6d1fd59b4+114740]\n\tGetHandleVerifier [0x0x7ff6d1fd5b69+115177]\n\tGetHandleVerifier [0x0x7ff6d1fbc368+10728]\n\tBaseThreadInitThunk [0x0x7ffa253de8d7+23]\n\tRtlUserThreadStart [0x0x7ffa25ddc34c+44]\n",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001B[1;31mInvalidSessionIdException\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[6], line 91\u001B[0m\n\u001B[0;32m 89\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m:\n\u001B[0;32m 90\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m有误\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m---> 91\u001B[0m driver\u001B[38;5;241m.\u001B[39mfind_element(By\u001B[38;5;241m.\u001B[39mXPATH,\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m//*[@id=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtab-item-2\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m]/span[2]\u001B[39m\u001B[38;5;124m'\u001B[39m)\u001B[38;5;241m.\u001B[39mclick()\n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:748\u001B[0m, in \u001B[0;36mWebDriver.find_element\u001B[1;34m(self, by, value)\u001B[0m\n\u001B[0;32m 745\u001B[0m by \u001B[38;5;241m=\u001B[39m By\u001B[38;5;241m.\u001B[39mCSS_SELECTOR\n\u001B[0;32m 746\u001B[0m value \u001B[38;5;241m=\u001B[39m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m[name=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mvalue\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m]\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[1;32m--> 748\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mexecute(Command\u001B[38;5;241m.\u001B[39mFIND_ELEMENT, {\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124musing\u001B[39m\u001B[38;5;124m\"\u001B[39m: by, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m: value})[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py:354\u001B[0m, in \u001B[0;36mWebDriver.execute\u001B[1;34m(self, driver_command, params)\u001B[0m\n\u001B[0;32m 352\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mcommand_executor\u001B[38;5;241m.\u001B[39mexecute(driver_command, params)\n\u001B[0;32m 353\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m response:\n\u001B[1;32m--> 354\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39merror_handler\u001B[38;5;241m.\u001B[39mcheck_response(response)\n\u001B[0;32m 355\u001B[0m response[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_unwrap_value(response\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mvalue\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m))\n\u001B[0;32m 356\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m response\n",
"File \u001B[1;32mD:\\ProgramTools\\Anaconda\\Lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py:229\u001B[0m, in \u001B[0;36mErrorHandler.check_response\u001B[1;34m(self, response)\u001B[0m\n\u001B[0;32m 227\u001B[0m alert_text \u001B[38;5;241m=\u001B[39m value[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124malert\u001B[39m\u001B[38;5;124m\"\u001B[39m]\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtext\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m 228\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m exception_class(message, screen, stacktrace, alert_text) \u001B[38;5;66;03m# type: ignore[call-arg] # mypy is not smart enough here\u001B[39;00m\n\u001B[1;32m--> 229\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m exception_class(message, screen, stacktrace)\n",
"\u001B[1;31mInvalidSessionIdException\u001B[0m: Message: invalid session id\nStacktrace:\n\tGetHandleVerifier [0x0x7ff6d1fccda5+78885]\n\tGetHandleVerifier [0x0x7ff6d1fcce00+78976]\n\t(No symbol) [0x0x7ff6d1d899fc]\n\t(No symbol) [0x0x7ff6d1dd07df]\n\t(No symbol) [0x0x7ff6d1e08a52]\n\t(No symbol) [0x0x7ff6d1e03413]\n\t(No symbol) [0x0x7ff6d1e024d9]\n\t(No symbol) [0x0x7ff6d1d55d55]\n\tGetHandleVerifier [0x0x7ff6d22a4eed+3061101]\n\tGetHandleVerifier [0x0x7ff6d229f33d+3037629]\n\tGetHandleVerifier [0x0x7ff6d22be592+3165202]\n\tGetHandleVerifier [0x0x7ff6d1fe730e+186766]\n\tGetHandleVerifier [0x0x7ff6d1feeb3f+217535]\n\t(No symbol) [0x0x7ff6d1d54dca]\n\tGetHandleVerifier [0x0x7ff6d23c45e8+4238440]\n\tBaseThreadInitThunk [0x0x7ffa253de8d7+23]\n\tRtlUserThreadStart [0x0x7ffa25ddc34c+44]\n"
]
}
],
"execution_count": 6
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 维修历史导出"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from selenium import webdriver\n",
"from selenium.webdriver.support.ui import Select\n",
"from selenium.webdriver import ActionChains\n",
"import time\n",
"import xlrd\n",
"import xlwt\n",
"import re\n",
"import datetime\n",
"from xlutils.copy import copy\n",
"from selenium.webdriver.common.keys import Keys\n",
"from selenium.webdriver.common.action_chains import ActionChains\n",
"from selenium.webdriver.common.by import By\n",
"import pandas as pd\n",
"\n",
"# 登录\n",
"name = '18132039923'\n",
"password = 'jl123456'\n",
"option_chrome = webdriver.ChromeOptions()\n",
"option_chrome.add_argument('--headless')\n",
"http='https://qixiu.dada365.com/login'\n",
"driver = webdriver.Chrome(executable_path=r'C:\\chromedriver\\chromedriver_99\\chromedriver.exe')\n",
"driver.maximize_window()\n",
"driver.implicitly_wait(1)\n",
"driver.get(http)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[1]/div/div/input').send_keys(name)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[2]/div/div/input').send_keys(password)\n",
"time.sleep(1)\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div/div/div/form/div[4]/div/button/span').click()\n",
"time.sleep(4)\n",
"# 点击工单管理\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[1]/div[1]/ul/div/div[2]/li/div/span').click()\n",
"time.sleep(2)\n",
"# 点击工单查询\n",
"driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[1]/div[1]/div[1]/ul/li[1]/div/p').click()\n",
"\n",
"# '/html/body/div[3]/ul/li[2]/span'\n",
"# 点击已收款\n",
"driver.find_element(By.XPATH,'//*[@id=\"tab-paid\"]').click()\n",
"# 点击500条每页\n",
"time.sleep(2)\n",
"driver.find_element(By.XPATH,'//*[@id=\"pane-paid\"]/div/div[2]/div/span[2]/div/div[1]/span/span/i').click()\n",
"\n",
"time.sleep(3)\n",
"driver.find_element(By.XPATH,'//html/body/div[3]/div[1]/div[1]/ul/li[6]/span').click()\n",
"\n",
"# 点击查看\n",
"for j in range(2,5):\n",
" for h in range(1,501):\n",
" driver.find_element(By.XPATH,'//*[@id=\"pane-paid\"]/div/div[1]/div/div[3]/table/tbody/tr[%s]/td[10]/div/div/button[1]/span'%h).click()\n",
" time.sleep(2)\n",
" GD_num=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[1]/ul/li[1]')\n",
" start_date=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[2]/li[1]')\n",
" car_no_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[1]/li[1]')\n",
" name_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[1]/li[2]')\n",
" phone_num_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[1]/li[3]')\n",
" car_model_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[1]/li[4]/strong')\n",
" mile=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[2]/li[2]')\n",
" tech_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[2]/li[3]')\n",
" vin_GD=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[2]/ul[2]/li[4]')\n",
" print()\n",
" print(GD_num.text,\"@\",start_date.text,\"@\",car_no_GD.text,\"@\",name_GD.text,\"@\",phone_num_GD.text,\"@\",car_model_GD.text,\"@\",mile.text,\"@\",tech_GD.text,\"@\",vin_GD.text,\"@\")\n",
" try:\n",
" for c in range(2,100):\n",
" print(GD_num.text,end=\" 材料历史:\")\n",
" for d in range(2,15):\n",
" cl=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[3]/div[2]/table/tr[%s]/td[%s]'%(c,d))\n",
" print(cl.text,end=\"@\")\n",
" if d==14:\n",
" print()\n",
" except:\n",
" pass\n",
" print()\n",
" try:\n",
" for e in range(2,100):\n",
" print(GD_num.text,end=\" 项目历史:\")\n",
" for f in range(2,8):\n",
" if cl.text!=\"\":\n",
" xm=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div/div[3]/div[4]/table/tr[%s]/td[%s]'%(e,f))\n",
" # //*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[3]/div[4]/table/tr[2]/td[2]/span\n",
" # //*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[3]/div[4]/table/tr[2]/td[3]\n",
" # //*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[3]/div[4]/table/tr[2]/td[4]\n",
" # //*[@id=\"app\"]/div/div[2]/div[2]/div[3]/div[3]/div[4]/table/tr[2]/td[7]\n",
" else:\n",
" xm=driver.find_element(By.XPATH,'//*[@id=\"app\"]/div/div[2]/div[2]/div/div[4]/div[2]/table/tr[%s]/td[%s]/span'%(e,f))\n",
" print(xm.text,end=\"@\")\n",
" if f==7:\n",
" print()\n",
" except:\n",
" pass\n",
" driver.find_element(By.XPATH,'//*[@id=\"tab-item-2\"]/span[2]').click()\n",
"# 翻页\n",
" driver.find_element(By.XPATH,'//*[@id=\"pane-paid\"]/div/div[2]/div/ul/li[%s]'%j).click()"
]
}
],
"metadata": {
"interpreter": {
"hash": "59310123ccd3619229d524789fb6029e22b3ae7206c94adf033078aa9a774872"
},
"kernelspec": {
"display_name": "Python 3.9.6 ('F6')",
"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.6"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}