与Playwright一起在异步代码中遇到NotImplementedError:了解原因并寻求解决方案

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

我在使用 Playwright 运行异步代码时遇到了

NotImplementedError
。您能帮助我了解此错误的根本原因并提出可能的解决方案吗?

这是我运行的代码:

html = await get_html(url, "#content .filter")

但我认为错误来自这里:

async def get_html(url, selector, sleep=5, retries=3):
    html = None
    for i in range(1, retries+1):
        time.sleep(sleep * i)
        try:
            async with async_playwright() as p:
                browser = await p.chromium.launch()
                page = await browser.new_page()
                await page.goto(url)
                print(await page.title())
                html = await page.inner_html(selector)
        except PlaywrightTimeout:
            print(f"Timeout error on {url}")
            continue
        else:
            break
    return html

我将 chromium 更改为 Firefox 但它仍然给我同样的错误

这是我运行的代码:

html = await get_html(url, "#content .filter")

这就是我所期待的: 2015-16 NBA 赛程 |篮球参考网

web-scraping webdriver subprocess python-asyncio playwright
1个回答
0
投票

https://github.com/microsoft/playwright-python/issues/178#issuecomment-1302869947

该链接提供了对该问题的一些见解。就我个人而言,我在 venv 中运行代码,因此我必须为我的 venv 找到 kernel.py

© www.soinside.com 2019 - 2024. All rights reserved.