diff --git a/nonebot_plugin_fortnite/pve.py b/nonebot_plugin_fortnite/pve.py index 9aa9ee5..ad9eafc 100644 --- a/nonebot_plugin_fortnite/pve.py +++ b/nonebot_plugin_fortnite/pve.py @@ -5,6 +5,9 @@ from .config import data_dir vb_file = data_dir / "vb.png" +hot_info_1_path = data_dir / 'hot_info_1.png' +container_hidden_xs_path = data_dir / 'container_hidden_xs.png' +hot_info_2_path = data_dir / 'hot_info_2.png' async def screenshot_vb_img() -> Path: url = "https://freethevbucks.com/timed-missions" @@ -20,22 +23,28 @@ async def screenshot_vb_img() -> Path: async def take_screenshot(locator, path): try: await locator.scroll_into_view_if_needed() - await locator.wait_for_element_state('visible', timeout=5000) - await locator.screenshot(path=path) + + # 检查元素内容是否为空 + content = await locator.inner_html() + if content.strip(): # 如果内容不为空 + await asyncio.wait_for(locator.screenshot(path=path), timeout=5) + else: + logger.warning(f"Locator for {path.name} is empty.") except Exception: pass + # 截取第一个
hot_info_1 = page.locator('div.hot-info').nth(0) - await take_screenshot(hot_info_1, data_dir / 'hot_info_1.png') + await take_screenshot(hot_info_1, hot_info_1_path) # 截取