diff --git a/LittlePaimon/plugins/Mihoyo_bbs/__init__.py b/LittlePaimon/plugins/Mihoyo_bbs/__init__.py index 06361a7..c5dd083 100644 --- a/LittlePaimon/plugins/Mihoyo_bbs/__init__.py +++ b/LittlePaimon/plugins/Mihoyo_bbs/__init__.py @@ -29,8 +29,8 @@ post_screenshot = on_regex(r'(https://)?(m\.)?bbs.mihoyo.com/.+/article/\d+', pr async def _(event: MessageEvent, url: str = RegexMatched()): logger.info('米游社', f'开始截图帖子{url}') try: - img = await screenshot(url, elements=['.mhy-article-page__main']) + img = await screenshot(url, elements=['.mhy-article-page__main'], timeout=180000) except Exception: logger.info('米游社', f'帖子{url}截图失败') - return + await post_screenshot.finish('米游社帖子截图超时失败了~~') await post_screenshot.finish(MessageSegment.image(img)) diff --git a/LittlePaimon/utils/brower.py b/LittlePaimon/utils/brower.py index a93c261..e76f8e6 100644 --- a/LittlePaimon/utils/brower.py +++ b/LittlePaimon/utils/brower.py @@ -19,7 +19,7 @@ async def start_browser(): global _browser try: _playwright = await async_playwright().start() - _browser = await _playwright.chromium.launch() + _browser = await _playwright.chromium.launch(headless=True) except NotImplementedError: logger.warning('Playwright', '初始化失败,请关闭FASTAPI_RELOAD') except Exception as e: @@ -49,8 +49,8 @@ async def get_new_page(**kwargs) -> AsyncGenerator[Page, None]: async def screenshot(url: str, *, elements: Optional[Union[List[str]]] = None, - timeout: Optional[float] = 60000, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = "networkidle", + timeout: Optional[float] = 100000, + wait_until: Literal["domcontentloaded", "load", "networkidle", "load", "commit"] = "networkidle", viewport_size: Tuple[int, int] = (1920, 1080), full_page=True, **kwargs): @@ -67,7 +67,7 @@ async def screenshot(url: str, if not elements: return await page.screenshot(timeout=timeout, full_page=full_page) for e in elements: - card = await page.query_selector(e) + card = await page.wait_for_selector(e, timeout=timeout, state='visible') assert card clip = await card.bounding_box() return await page.screenshot(clip=clip, timeout=timeout, full_page=full_page, path='test.png')