entari-plugin-browser
Browser API service for Entari using Playwright
使用
导入
from entari_plugin_browser import playwright_api, text2img
async def main():
async with playwright_api.page() as page:
await page.goto('https://www.baidu.com')
await page.screenshot(path='baidu.png')
img: bytes = await text2img('Hello, World!')
配置
在你的 Entari 配置文件中如下配置:(以 entari.yml 为例)
plugins:
browser:
browser_type: chromium
channel: chrome
headless: true
# ...
# 更多配置请参考 Playwright 文档,详见 <https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch>
HTMLRenderer
除了内置提供的 text2img 和 md2img 方法外,你还可以使用 HTMLRenderer 等来自定义渲染器。
from entari_plugin_browser import HTMLRenderer, convert_md, PageOption, ScreenshotOption
md = """\
<div align="center">
# entari-plugin-browser
*Browser API service for Entari using Playwright*
</div>
## 使用
### 导入
from entari_plugin_browser import playwright_api, text2img
async def main():
async with playwright_api.page() as page:
await page.goto('https://www.baidu.com')
await page.screenshot(path='baidu.png')
img: bytes = await text2img('Hello, World!')
"""
async def function():
image_bytes: bytes = await HTMLRenderer().render(
convert_md(md),
extra_page_option=PageOption(viewport={"width": 840, "height": 10}, device_scale_factor=1.5),
extra_screenshot_option=ScreenshotOption(type="jpeg", quality=80, scale="device"),
)
模板转图片(可选依赖 jinja2)
如需将 Jinja2 模板渲染为 HTML 并输出图片,安装可选依赖:
pip install "entari-plugin-browser[jinja2]"
示例:
from entari_plugin_browser import template2img
async def main():
text_list = ["1", "2", "3", "4"]
template_path = "path/to/templates"
template_name = "example.html"
img: bytes = await template2img(
template_path=template_path,
template_name=template_name,
templates={"text_list": text_list},
)
说明:默认启用 HTML 自动转义,如需插入已转义 HTML,请在模板中使用 |safe 过滤器。
Metadata
Release files for entari-plugin-browser 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| entari_plugin_browser-0.6.2.tar.gz | 16.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| entari_plugin_browser-0.6.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.9 kB
Release files / entari_plugin_browser-0.6.2.tar.gz
| Download URL | entari_plugin_browser-0.6.2.tar.gz |
|---|---|
| Size | 16.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbb8ee777602aa8b21ea8e24966c1ce3675910ee4318f8584d03ac2b887d5629
|
|
BLAKE2b-256 checksum How to use checksums |
37b43ccb03dd84a595056306ea90d95e9b2f9c148006bd3569c82f1a512d66a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.28.0 CPython/3.11.7 Windows/10
|
Release files / entari_plugin_browser-0.6.2-py3-none-any.whl
| Download URL | entari_plugin_browser-0.6.2-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42a7e65b49fdff338c6ade32d359a9d7de5b0aa076869f9eca0d2e7f4731667e
|
|
BLAKE2b-256 checksum How to use checksums |
593c7f193d6923bc5ce424f9c143383a93d327a17b93ce89f6ad62d8a350684d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.28.0 CPython/3.11.7 Windows/10
|
Security for entari-plugin-browser 0.6.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.