Commit 451a6662 by lei

1

parent 04fa942b
...@@ -226,65 +226,64 @@ class ToWork: ...@@ -226,65 +226,64 @@ class ToWork:
async def check_img_load_process(self, page, task): async def check_img_load_process(self, page, task):
logger.info('开始检测任务状态') logger.info('开始检测任务状态')
# 先写单个任务的,获取最后一张图片 # 先写单个任务的,获取最后一张图片
# 获取开始时间
start_time = get_current_time()
while True: while True:
# 获取开始时间 # 再次获取当前时间
start_time = get_current_time() current_time = get_current_time()
while True: # 最多等待一分钟
# 再次获取当前时间 if current_time - start_time >= 60:
current_time = get_current_time() # end
# 最多等待一分钟 await self.img_callback(task, '', '任务已超时')
if current_time - start_time >= 60: break
# end cur_type = 1 # 获取最后一个
await self.img_callback(task, '', '任务已超时') if cur_type == 1:
break # 判断文字中是否存在进度条
cur_type = 1 # 获取最后一个 text_path = '//div[contains(@id, "message-content-")]'
if cur_type == 1: text_el = await self.FindElement(page, text_path, 'last')
# 判断文字中是否存在进度条 if text_el:
text_path = '//div[contains(@id, "message-content-")]' title = await page.evaluate('(element) => element.textContent', text_el)
text_el = await self.FindElement(page, text_path, 'last') # 判断失败
if text_el: if 'Failed to process your command' in title or 'Sorry! Could not complete the job' in title:
title = await page.evaluate('(element) => element.textContent', text_el) logger.info('本次任务失败')
# 判断失败 # 回调
if 'Failed to process your command' in title or 'Sorry! Could not complete the job' in title: await self.img_callback(task, '', title)
logger.info('本次任务失败') return
# 回调 elif '%)' not in title and '(Waiting to start)' not in title and '正在发送命令' not in title and 'fast' in title:
await self.img_callback(task, '', title) logger.info('任务完成')
return # 最后一个链接
elif '%)' not in title and '(Waiting to start)' not in title and '正在发送命令' not in title and 'fast' in title: '//*[@id="message-accessories-1095187577776124025"]/div[1]/div/div/div/div/div/a'
logger.info('任务完成') img_path = '//*[contains(@id, "message-accessories-")]/div[1]/div/div/div/div/div/a'
# 最后一个链接 img_el = await self.FindElement(page, img_path, 'last')
'//*[@id="message-accessories-1095187577776124025"]/div[1]/div/div/div/div/div/a' if img_el:
img_path = '//*[contains(@id, "message-accessories-")]/div[1]/div/div/div/div/div/a' href = await page.evaluate('img_el => img_el.href', img_el)
img_el = await self.FindElement(page, img_path, 'last') if href:
if img_el: logger.info(href)
href = await page.evaluate('img_el => img_el.href', img_el) # 回调
if href: await self.img_callback(task, href)
logger.info(href) return
# 回调
await self.img_callback(task, href)
return
else:
logger.info('任务进行中')
else: else:
logger.info('文本元素不存在') logger.info('任务进行中')
else: else:
# 开始判断 logger.info('文本元素不存在')
element = '//ol[@data-list-id="chat-messages"]/li' else:
# 消息列表 # 开始判断
message_list = await self.CheckElement(page, element, 20, 'list') element = '//ol[@data-list-id="chat-messages"]/li'
if message_list: # 消息列表
logger.info('消息列表存在') message_list = await self.CheckElement(page, element, 20, 'list')
# 找到所有子元素 if message_list:
for e in message_list: logger.info('消息列表存在')
# 找到文本并匹配 # 找到所有子元素
path = '//div[contains(@id, "message-content-")]/strong' for e in message_list:
label_element = await self.FindElement(e, path) # 找到文本并匹配
if label_element: path = '//div[contains(@id, "message-content-")]/strong'
title = await page.evaluate('(element) => element.textContent', label_element) label_element = await self.FindElement(e, path)
logger.info(title) if label_element:
else: title = await page.evaluate('(element) => element.textContent', label_element)
logger.info('未找到文本') logger.info(title)
await asyncio.sleep(1) else:
logger.info('未找到文本')
await asyncio.sleep(1)
# 循环输入指令 # 循环输入指令
async def enter_prompt(self, page, tasks): async def enter_prompt(self, page, tasks):
......
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