From 37a1875abc65a6c0afa5db2ed602589efff1cecf Mon Sep 17 00:00:00 2001
From: CMHopeSunshine <277073121@qq.com>
Date: Sat, 8 Oct 2022 15:09:06 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=8A=A0=E9=95=BF`=E7=BD=91?=
=?UTF-8?q?=E9=A1=B5=E6=88=AA=E5=9B=BE`=E7=9A=84=E7=AD=89=E5=BE=85?=
=?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=8C=E6=8F=90=E9=AB=98=E6=88=AA=E5=9B=BE?=
=?UTF-8?q?=E6=88=90=E5=8A=9F=E7=8E=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LittlePaimon/plugins/Mihoyo_bbs/__init__.py | 4 ++--
LittlePaimon/utils/brower.py | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
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')