Skip to main content

Browser API service for Entari using Playwright

Project description

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

除了内置提供的 text2imgmd2img 方法外,你还可以使用 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"),
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

entari_plugin_browser-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

entari_plugin_browser-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file entari_plugin_browser-0.1.0.tar.gz.

File metadata

  • Download URL: entari_plugin_browser-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.19.1 CPython/3.9.13 Windows/10

File hashes

Hashes for entari_plugin_browser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45cc630424e1c9d3662598387ec0b1cfabee782e6926724c7d08789f2c057775
MD5 421135fd8f1ddd17cbfe2a135c1ade98
BLAKE2b-256 0fa014fb5d833c848325afebd578e1a6b6c9590df184cd8f51c450d89b8a0a6c

See more details on using hashes here.

File details

Details for the file entari_plugin_browser-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for entari_plugin_browser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a0d82d9e8a30e7e6862b7decb1d8ca4c3afe3236b244d64ad2e5136d4b0662d
MD5 1f83e55d38eaf301b96550741179399f
BLAKE2b-256 91e7b2ee938862d95768ba893bd1d71cb7905db4d3907598a8a60e73a5b546d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page