nonebot-plugin-htmlrender 0.6.1__py3-none-any.whl → 0.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,7 +61,7 @@ async def init_browser(**kwargs) -> Browser:
61
61
  @asynccontextmanager
62
62
  async def get_new_page(device_scale_factor: float = 2, **kwargs) -> AsyncIterator[Page]:
63
63
  """
64
- 获取一个新的页面的上下文管理器。
64
+ 获取一个新的页面的上下文管理器, 这里的 page 默认使用设备缩放因子为 2。
65
65
 
66
66
  Args:
67
67
  device_scale_factor (float): 设备缩放因子。
@@ -284,17 +284,32 @@ async def template_to_pic(
284
284
  async def capture_element(
285
285
  url: str,
286
286
  element: str,
287
- timeout: float = 0,
288
- type: Literal["jpeg", "png"] = "png",
289
- quality: Union[int, None] = None,
290
- screenshot_timeout: Optional[float] = 30_000,
291
- **kwargs,
287
+ page_kwargs: Optional[dict] = None,
288
+ goto_kwargs: Optional[dict] = None,
289
+ screenshot_kwargs: Optional[dict] = None,
292
290
  ) -> bytes:
293
- async with get_new_page(**kwargs) as page:
294
- page.on("console", lambda msg: logger.debug(f"浏览器控制台: {msg.text}"))
295
- await page.goto(url, timeout=timeout)
296
- return await page.locator(element).screenshot(
297
- type=type,
298
- quality=quality,
299
- timeout=screenshot_timeout,
291
+ """捕获网页中指定元素的截图, 通过CSS选择器或XPath表达式指定元素。
292
+
293
+ Args:
294
+ url: 目标网页URL
295
+ element: CSS选择器或XPath表达式
296
+ page_kwargs: 传递给get_new_page的参数
297
+ goto_kwargs: 传递给page.goto方法的额外参数
298
+ screenshot_kwargs: 传递给screenshot方法的额外参数
299
+
300
+ Returns:
301
+ bytes: 元素截图数据
302
+ """
303
+ page_kwargs = page_kwargs or {}
304
+ goto_kwargs = goto_kwargs or {}
305
+ screenshot_kwargs = screenshot_kwargs or {}
306
+
307
+ async with get_new_page(**page_kwargs) as page:
308
+ page.on(
309
+ "console",
310
+ lambda msg: logger.opt(colors=True).debug(
311
+ f"<cyan>[Browser Console]</cyan> {msg.text}"
312
+ ),
300
313
  )
314
+ await page.goto(url, **goto_kwargs)
315
+ return await page.locator(element).screenshot(**screenshot_kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-htmlrender
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary: 通过浏览器渲染图片
5
5
  Project-URL: Homepage, https://github.com/kexue-z/nonebot-plugin-htmlrender
6
6
  Project-URL: Bug Tracker, https://github.com/kexue-z/nonebot-plugin-htmlrender/issues
@@ -1,9 +1,9 @@
1
1
  nonebot_plugin_htmlrender/__init__.py,sha256=fzqf-XaZ_lxzr18kHgxD16Zq4BaU2e-UidoHGVzDyHg,1825
2
- nonebot_plugin_htmlrender/browser.py,sha256=jjj43q82-zMZsmR2gJx9tymwoG8piODuaZz8Sp6FUAY,4873
2
+ nonebot_plugin_htmlrender/browser.py,sha256=zMdFvDQrZ1sZtV6c3Kh7RAwj4FBcoWA85jt147-4jaA,4925
3
3
  nonebot_plugin_htmlrender/compat.py,sha256=eeAOMbJB0qMYkUmO8pbM11hxGCZuVUQ2sYEy8XTV81g,826
4
4
  nonebot_plugin_htmlrender/config.py,sha256=-fywpLhQHVCZ2s6c3wG5ywREZbUFcW9ZKrrRj8ptEfQ,2272
5
5
  nonebot_plugin_htmlrender/consts.py,sha256=eMujEJaBDsQw8wwIJH3sb3twS0eo7jCiQd-TD671950,930
6
- nonebot_plugin_htmlrender/data_source.py,sha256=OBzIYZHTIzffD9Jsl7GBkpc3jYuYaMmJWusEFi_ckyE,9757
6
+ nonebot_plugin_htmlrender/data_source.py,sha256=rFHyW0JYFRI9bhnbGHRw8c7sMWGMkvpb66LziFn2Ns0,10270
7
7
  nonebot_plugin_htmlrender/install.py,sha256=ejfoPkyixHN83ldFhNihCGA25IjOLqtncEjEbh_C6Sw,8186
8
8
  nonebot_plugin_htmlrender/process.py,sha256=BqU0GBj_NYl5mSxyVIpF35PApcQDjiF3jT6hdhLqniA,4526
9
9
  nonebot_plugin_htmlrender/signal.py,sha256=sOOqIns5QIi5404mZoEtt3ssliXS3IGndkt0WMreNe0,3920
@@ -17,7 +17,7 @@ nonebot_plugin_htmlrender/templates/katex/katex.min.b64_fonts.css,sha256=8KXk7iV
17
17
  nonebot_plugin_htmlrender/templates/katex/katex.min.js,sha256=cXQ4tsltOzinSxpNqnPldAdfpstIPXBDKihVb7ccZL0,270288
18
18
  nonebot_plugin_htmlrender/templates/katex/mathtex-script-type.min.js,sha256=d-R93Fs6-ZBEU3VEH7u_qz-b02iCPKEPmLJEgRf2-MU,1290
19
19
  nonebot_plugin_htmlrender/templates/katex/mhchem.min.js,sha256=8MoD3xlLjD1gF_9FXbag75iFeQVmP6MRps3teIsVNAs,33730
20
- nonebot_plugin_htmlrender-0.6.1.dist-info/METADATA,sha256=QbO5wbRG-EgEbL4uzFvJTE4KbKKzkK_n6_s_hadSdBI,6721
21
- nonebot_plugin_htmlrender-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
- nonebot_plugin_htmlrender-0.6.1.dist-info/licenses/LICENSE,sha256=4HHgpu3ihnBZ9AVZDgOzGnAJRt8W7IQo5VSBEJKRr5g,1062
23
- nonebot_plugin_htmlrender-0.6.1.dist-info/RECORD,,
20
+ nonebot_plugin_htmlrender-0.6.2.dist-info/METADATA,sha256=7S6E1LOFfirWqx_jpJyzesvje_g23NKUJuRnPSX_hzM,6721
21
+ nonebot_plugin_htmlrender-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
22
+ nonebot_plugin_htmlrender-0.6.2.dist-info/licenses/LICENSE,sha256=4HHgpu3ihnBZ9AVZDgOzGnAJRt8W7IQo5VSBEJKRr5g,1062
23
+ nonebot_plugin_htmlrender-0.6.2.dist-info/RECORD,,