I am trying to use Playwright to listen event in browser continuously,but it seems that if I don't use browser.close(),it cannot keep listening either.
我试着用PlayWright连续监听浏览器中的事件,但如果我不使用Browser.lose(),它似乎也无法继续监听。
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.on('response', on_response)
page.goto('https://sport.dgut.edu.cn')
after running this, Playwright exit automatically.
if I swap page.on and page.goto,it will like this:
运行此命令后,编剧会自动退出。如果我交换Page.On和Page.goto,它将如下所示:
Future exception was never retrieved
future: <Future finished exception=Error('Connection closed')>
playwright._impl._api_types.Error: Connection closed
更多回答
What's the definition for on_response
and what are you really trying to accomplish here? Usually, if you're trying to wait for a particular response, you'd use page.expect_response
.
On_Response的定义是什么?你在这里真正想要实现的是什么?通常,如果您正在尝试等待特定的响应,则可以使用page.expect_Response。
优秀答案推荐
我是一名优秀的程序员,十分优秀!