ClericPy / ichrome

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.
https://pypi.org/project/ichrome/
MIT License
227 stars 29 forks source link

async with 怎么封装成类 #102

Closed zenghh closed 1 year ago

zenghh commented 1 year ago
import asyncio

from ichrome import AsyncChromeDaemon

async def main():
    async with AsyncChromeDaemon() as cd:
        proxy = None
        async with cd.incognito_tab(proxyServer=proxy) as tab:
            # This tab will be created in the given BrowserContext
            await tab.goto('http://httpbin.org/ip', timeout=10)
            # print and watch your IP changed
            print(await tab.html)

asyncio.run(main())

比如示例中这段代码,我如果想封装成类,在类中使用需要怎么改,谢谢

ClericPy commented 1 year ago

async with 主要就是 __aenter__ __aexit__ 方法