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

how to use chromedeamon multiple without running from cmd ? #141

Closed irfanykywz closed 11 months ago

irfanykywz commented 11 months ago

i want my code run multiple chrome at same time but its always blocking process

here my code

    async def logic(self):
        for i, (url) in enumerate(self.session):
            async with AsyncChromeDaemon(headless=0, disable_image=False, port=(999 + i+1)) as cd:
                async with cd.connect_tab(index=0, auto_close=False) as tab:
                    # tab: AsyncTab
                    await tab.goto(url)

                    self.callback()
irfanykywz commented 11 months ago

finaly i gix my code ;3

async def test(ports):
    async with AsyncChromeDaemon(
        chrome_path=None,
        host="127.0.0.1",
        port=ports,
        headless=False,
        user_agent=None,
        proxy=None,
        user_data_dir=None,
        disable_image=False,
        start_url="about:blank",
        extra_config=None,
        max_deaths=1,
        daemon=True,
        block=False,
        timeout=3,
        debug=False,
        proc_check_interval=5,
        on_startup=None,
        on_shutdown=None,
        before_startup=None,
        after_shutdown=None,
        clear_after_shutdown=False,
        ) as cd:
        # create a new tab
        async with cd.connect_tab(index=0) as tab:
            await tab.goto('https://github.com/ClericPy/ichrome', timeout=5)
            print(await tab.title)          

async def main():
    await asyncio.gather(
        test(9999),
        test(9998),
        test(9997)
    )

x = asyncio.run(main())
print(x)