如何让剧作家等待,直到Python中出现特定的cookie(然后返回它)?

问题描述 投票:0回答:1

我正在制作一个 python 脚本,通过 playwright webdriver 请求用户提供 cookie

这是我的虚拟代码

import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(headless=False)
        context = await browser.new_context()
        page = await context.new_page()
        await page.goto('https://example.com')
        print('Please log-in')
        while True:
            for i in (await context.cookies()):
                if i['name'] == 'account_cookie':
                    return i['value']
asyncio.run(main())
python playwright playwright-python
1个回答
0
投票

你可以使用

wait_for_function
:

await page.wait_for_function("document.cookie.includes('account_cookie')")
© www.soinside.com 2019 - 2024. All rights reserved.