From e2276e0546286f2221fa1d41b716b28f75d801a3 Mon Sep 17 00:00:00 2001 From: "shuohigh@gmail.com" Date: Wed, 21 May 2025 16:08:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EPlaywrightRPA=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .runtime.env | 2 +- pyproject_rpa.toml | 13 +++++++++++++ src/cluster/rpa.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pyproject_rpa.toml create mode 100644 src/cluster/rpa.py diff --git a/.runtime.env b/.runtime.env index 5229e3c..dbc5e5b 100644 --- a/.runtime.env +++ b/.runtime.env @@ -1,5 +1,5 @@ MODAL_ENVIRONMENT=dev -modal_app_name=cluster-test +modal_app_name=bowong-ai-video S3_mount_dir=/mntS3 S3_bucket_name=modal-media-cache S3_region=ap-northeast-2 diff --git a/pyproject_rpa.toml b/pyproject_rpa.toml new file mode 100644 index 0000000..f4a937e --- /dev/null +++ b/pyproject_rpa.toml @@ -0,0 +1,13 @@ +[project] +name = "PlaywrightRPA" +version = "0.0.1" +authors = [ + { name = "Yudi Xiao", email = "xyd@bowong.ai" }, +] +description = "基于Playwright处理抖音Web页面RPA" + +requires-python = ">=3.11" +dependencies = [ + "loguru>=0.7.3", + "playwright>=1.52.0" +] diff --git a/src/cluster/rpa.py b/src/cluster/rpa.py new file mode 100644 index 0000000..0376a9c --- /dev/null +++ b/src/cluster/rpa.py @@ -0,0 +1,33 @@ +import modal + +rpa_image = (modal.Image.debian_slim(python_version="3.11") + .pip_install_from_pyproject("../pyproject_rpa.toml") + .env({"PLAYWRIGHT_BROWSERS_PATH": "/root/browsers"}) + .run_commands("mkdir /root/browsers") + .run_commands("playwright install-deps") + .run_commands("playwright install chromium") + .add_local_python_source('cluster') + ) +app = modal.App(name='rpa', image=rpa_image, include_source=False) + +with rpa_image.imports(): + from loguru import logger + from playwright.async_api import async_playwright + + + @app.function() + async def rpa_run(webcast_id: str): + async with async_playwright() as p: + browser = await p.chromium.launch() + page = await browser.new_page() + await page.goto(f"https://live.douyin.com/{webcast_id}") + title = await page.title() + return title + + + @app.local_entrypoint() + async def local_run(): + logger.info(f"本地运行测试") + fn = modal.Function.from_name("rpa", "rpa_run") + title = await fn.remote.aio(webcast_id="333555252930") + logger.info(f"title = {title}")