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

why tab is none when I use ChromeDaemon? #136

Closed juanfrilla closed 1 year ago

juanfrilla commented 1 year ago
from ichrome import ChromeDaemon, Chrome, logger

def on_startup(chromed):
    chromed.started = 1

def on_shutdown(chromed):
    chromed.__class__.bye = 1

with ChromeDaemon(host="127.0.0.1",
                    port=9222,
                    max_deaths=1,
                    on_startup=on_startup,
                    on_shutdown=on_shutdown) as chromed:
    assert chromed.started
    logger.info(chromed)
    # create connection to Chrome Devtools
    chrome = Chrome(host="127.0.0.1", port=9222, timeout=3, retry=1)
    # now create a new tab without url
    tab = chrome.new_tab()
    # add a default callback
    test_cache = []
    tab._default_recv_callback.append(
        lambda tab, data: test_cache.append(data))
    # reset the url to bing.com, if loading time more than 5 seconds, will stop loading.
    # if inject js success, will alert Vue
    tab.set_url("https://www.bing.com/",
                referrer="https://www.github.com/",
                timeout=5)

Here, when I use tab = chrome.new_tab()tab is None, why?

ClericPy commented 1 year ago

old chrome cdp api is not available for now: Using unsafe HTTP verb GET to invoke /json/new. This action supports only PUT verb.

The old synchronous version is no longer being updated, so it's no longer usable. If you cannot accept the coroutine usage, you may want to try playwright-python from Microsoft.

juanfrilla commented 1 year ago

Okay, thanks, so I'll continue using asynchronous ichrome (the downside of async is that it adds complexity if I add it to my scrapy project), playwright-python i cannot use it because I'm using centOS in my server and is not supported by plawright

ClericPy commented 1 year ago

sync version ichrome is hard to stop (for threading's native issue), and I was a noob when started writing ichrome so that I was not able to abstract synchronous and asynchronous models into a unified architecture.

They are all problems left over from history. Now that I have been working on a salary cut and I am very busy, I don’t have the energy to maintain two sets of codes at the same time.

juanfrilla commented 1 year ago

thanks @ClericPy don't worry. Ichrome for me it's a good tool and I can adapt to asynchronous ichrome, I'm using because playwright is not supported by my server and selenium (undetected-chromedriver) it's prone to trouble. So ichrome it's the only alternative I have

ClericPy commented 1 year ago

most other choices most have been dead for years, https://github.com/pyppeteer/pyppeteer is also dead ...

playwright has many language versions, and it has official docker image for server system issues