需要在Asyncio循环内运行Playwright同步API

2024-04-27 16:41:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用Discord.py库创建一个Discord Bot。机器人的任务之一是使用其他API检查最新的Youtube视频、TikTok等。我正在使用TikTokApi对TikTok内容进行解析。我的discord bot客户端中有一个计划任务,每5分钟运行一次:

def check_toks():
es_link = tktok.Tktok_catcher("ES")
en_link = tktok.Tktok_catcher("US")
print(es_link, en_link)

@tasks.loop(minutes=5)
async def check_platforms():
    es_link = tktok.Tktok_catcher("ES")

运行以下代码会导致以下错误:

playwright._impl._api_types.Error: It looks like you are using Playwright Sync API inside the asyncio loop. 
Please use the Async API instead.

是否有解决此问题的方法(一种在Asyncio循环中运行playwright sync API的方法),或者在我使用的库中是否有需要更改的内容以使其正常工作


Tags: loopapi内容esdefchecklinken