Commit b8a2e595 authored by 邱阿朋's avatar 邱阿朋

fix(vc): 优化销售数据导出功能

- 添加异常处理,解决元素未找到时的刷新重试问题
- 优化等待和刷新逻辑,提高导出成功率- 引入 ElementNotFoundError 异常类,用于捕获元素未找到的异常
parent db70747a
# coding: utf-8 # coding: utf-8
import pandas as pd import pandas as pd
from DrissionPage.errors import ElementNotFoundError
from app.vc import rabbit from app.vc import rabbit
from app.helper import domain, file from app.helper import domain, file
...@@ -42,26 +43,31 @@ class ProductSales(AutoInterface): ...@@ -42,26 +43,31 @@ class ProductSales(AutoInterface):
self.page.ele("#raw_xlsx_btn").click() self.page.ele("#raw_xlsx_btn").click()
self.logger.debug("点击导出等待下载任务提交...") self.logger.debug("点击导出等待下载任务提交...")
self.page.wait(3)
while True: while True:
self.page.ele("#downloadManager").click() try:
self.logger.debug("等待数据加载...") self.page.wait(3)
self.page.wait(5)
self.page.ele("#downloadManager").click()
# 使用 XPath 定位元素 self.logger.debug("等待数据加载...")
xpath = '//kat-table-body/kat-table-row[1]/kat-table-cell[@role="cell"][1]/a' self.page.wait(5)
link = self.page.ele(f'xpath:{xpath}')
if link is None: # 使用 XPath 定位元素
xpath = '//kat-table-body/kat-table-row[1]/kat-table-cell[@role="cell"][1]/a'
link = self.page.ele(f'xpath:{xpath}')
if link is None:
self.page.refresh()
continue
self.logger.debug("开始下载文件...")
# 点击下载链接
link.click.to_download(rename=self.result_file_name)
self.logger.debug("等待下载...")
file.wait_for_downloads(self.result_file_name, 3600)
break
except ElementNotFoundError:
self.page.refresh() self.page.refresh()
continue continue
self.logger.debug("开始下载文件...")
# 点击下载链接
link.click.to_download(rename=self.result_file_name)
self.logger.debug("等待下载...")
file.wait_for_downloads(self.result_file_name,3600)
break
def push_data_queue(self): def push_data_queue(self):
rabbit.connection() rabbit.connection()
rabbit.connect(queue='product_sales', routing_key='product_sales', exchange='reports') rabbit.connect(queue='product_sales', routing_key='product_sales', exchange='reports')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment