新增PlaywrightRPA 函数

This commit is contained in:
shuohigh@gmail.com 2025-05-21 16:08:01 +08:00
parent 629083210b
commit e2276e0546
3 changed files with 47 additions and 1 deletions

View File

@ -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

13
pyproject_rpa.toml Normal file
View File

@ -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"
]

33
src/cluster/rpa.py Normal file
View File

@ -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}")