Giter Site home page Giter Site logo

clericpy / ichrome Goto Github PK

View Code? Open in Web Editor NEW
226.0 9.0 29.0 1.66 MB

Chrome controller for Humans, based on Chrome Devtools Protocol(CDP) and python3.7+.

Home Page: https://pypi.org/project/ichrome/

License: MIT License

Python 100.00%
chrome python python37 torequests chrome-devtools-protocol cdp chrome-daemon python3 chrome-process-daemon daemon

ichrome's People

Contributors

auphofbsf avatar clericpy avatar t-256 avatar why2lyj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ichrome's Issues

how to selectall?

keyboard_send(type="rawKeyDown", key="Control+a")

this code is wrong

How do you take a screenshot ...

I want to take a screenshot of whatever on the page using this module. Currently, I am using pyppeteer. My plan is to use this from FastApi.

Any help is appreciated.
Thank you.

browser target context

How do I access the browser target?
The endpoint is exposed as webSocketDebuggerUrl in /json/version. Note the browser in the URL, rather than page. If Chrome was launched with --remote-debugging-port=0 and chose an open port, the browser endpoint is written to both stderr and the DevToolsActivePort file in browser profile folder.

https://chromedevtools.github.io/devtools-protocol/

chrome cdp do not support non-localhost without --headless, need the port forwarding

https://stackoverflow.com/questions/6827310/chrome-remote-debugging-doesnt-work-with-ip

The default chrome debug mode does not support non-headless mode when opening remote access:

  1. localhost + --headless runs ok
  2. localhost without --headless runs ok
  3. lan-ip + --headless runs ok
  4. lan-ip without headless fails

So far there is not any ways to fix it, so you should try some ways of forward proxy for this:

  • gost -L 172.1.1.11:9456/127.0.0.1:9234
  • ssh -L 0.0.0.0:9223:localhost:9222 localhost -N
  • nginx
  • others
import asyncio


class ForwardedConnection(asyncio.Protocol):

    def __init__(self, peer):
        self.peer = peer
        self.transport = None
        self.buff = []

    def connection_made(self, transport):
        self.transport = transport
        if self.buff:
            self.transport.writelines(self.buff)
            self.buff.clear()

    def data_received(self, data):
        self.peer.write(data)

    def connection_lost(self, e):
        if self.peer:
            self.peer.close()


class PortForwarder(asyncio.Protocol):

    def __init__(self, dst_host, dst_port):
        self.dst_host = dst_host
        self.dst_port = dst_port

    async def connection_daemon(self):
        try:
            await asyncio.get_running_loop().create_connection(
                lambda: self.fc, self.dst_host, self.dst_port)
        except Exception:
            return

    def connection_made(self, transport):
        self.transport = transport
        self.fc = ForwardedConnection(self.transport)
        asyncio.ensure_future(self.connection_daemon())

    def data_received(self, data):
        if self.fc.transport is None:
            self.fc.buff.append(data)
        else:
            self.fc.transport.write(data)

    def connection_lost(self, e):
        if self.fc.transport:
            self.fc.transport.close()

    @classmethod
    async def start_server(cls, dst_host, dst_port, src_host, src_port):
        server = await asyncio.get_running_loop().create_server(
            lambda: cls(dst_host, dst_port), src_host, src_port)
        return server


async def _main():
    server = await PortForwarder.start_server('127.0.0.1', 9222, '172.1.1.11',
                                              9221)
    await server.wait_closed()


def main():
    asyncio.run(_main())


if __name__ == '__main__':
    main()

How could I show some local variables in javascript with ichrome?

Sorry, I know this question that is related to Chrome DevTools Protocol.
But, I help you can help me. :(

I'd like to get some local variables in a javascript function.
My idea is setting some breakpoints, executing and then showing the debugger.scope to capture the local variables.
However, I don't know how to start with ichrome....

怎么注入js在页面js加载之前?

如题:

url = 'http://wcjs.sbj.cnipa.gov.cn/' 
await tab.js("""xxxx""")  # 此时注入js,页面还不存在,当goto时,页面就刷新了
await tab.goto(url)  # 在打开的同时,页面未加载js时,注入我的js

在不同的tab.js()构建的全局变量不通用

在同一个tab的两次.js()调用中,给window声明的全局变量不可通用,比如
// 第一次调用
tab.js(window.myslots = {};)
// 第二次调用
tab.js(window.myslots['property-key'] = "spam")
结果第二次报错:TypeError: Cannot set properties of undefined....
不知道这是什么原因?是不是我使用有错误?

How could I use Runtime.compileScript in ichrome?

I want to use this method(Runtime.compileScript) from Chrome DevTools Protocol in ichrome.
How could I use Runtime.compileScript in ichrome?
I just know the tab.js().
Could you give me an example?

btw, Debugger.setBreakpoint this method, I also need.

ChromeWorker failed to start when runnning with gunicorn.

[2021-09-23 10:42:03 +0000] [24978] [INFO] Starting gunicorn 20.1.0
[2021-09-23 10:42:03 +0000] [24978] [INFO] Listening at: http://0.0.0.0:19528 (24978)
[2021-09-23 10:42:03 +0000] [24978] [INFO] Using worker: gevent
[2021-09-23 10:42:03 +0000] [24982] [INFO] Booting worker with pid: 24982
[2021-09-23 10:42:03 +0000] [24983] [INFO] Booting worker with pid: 24983
[2021-09-23 10:42:03 +0000] [24984] [INFO] Booting worker with pid: 24984
INFO  2021-09-23 10:43:53 [ichrome] pool.py(470): [enqueue](0) ChromeTask(<9234>, PENDING, id=1, tab=None), timeout=None, data=<ichrome.pool._TabWorker object at 0x000000000875ae58>

The program works well with django dev python manage.py runserver 0.0.0.0:19528
Thank you very much for any help!

Demo raise "AttributeError: 'AsyncChromeDaemon' object has no attribute 'running'"

Python 3.8.8, in virtualenv environ, while I run the demo of ReadMe,
`λ python3 -m ichrome -t

from ichrome.debugger import *
tab = get_a_tab()`
it cry, and the tracebacks:

`Traceback (most recent call last):
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 220, in connect_a_chrome
return Chrome(host=host, port=port)
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 154, in init
ok = self.run_sync(self._self.connect())
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 54, in run_sync
return self.loop.run_until_complete(future)
File "d:\python38\lib\asyncio\base_events.py", line 592, in run_until_complete
self._check_running()
File "d:\python38\lib\asyncio\base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\async_utils.py", line 2085, in repl
result = eval(code, f_globals, f_locals)
File "", line 1, in
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 228, in get_a_tab
chrome = connect_a_chrome(host=host, port=port, **daemon_kwargs)
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 223, in connect_a_chrome
d = launch(host=host, port=port, **daemon_kwargs)
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 213, in launch
return Daemon(*args, **kwargs)
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 126, in init
self.run_sync(self._self.aenter())
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 54, in run_sync
return self.loop.run_until_complete(future)
File "d:\python38\lib\asyncio\base_events.py", line 592, in run_until_complete
self._check_running()
File "d:\python38\lib\asyncio\base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
Exception ignored in: <function Chrome.del at 0x0000020790AED160>
Traceback (most recent call last):
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\async_utils.py", line 2450, in del
_exhaust_simple_coro(self.close())
File "K:\python-works\ichrometesting\venv\lib\site-packages\torequests_py3_patch.py", line 153, in _exhaust_simple_coro
coro.send(None)
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\async_utils.py", line 2443, in close
if self.req:
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\async_utils.py", line 2290, in req
raise ChromeRuntimeError(
ichrome.exceptions.ChromeRuntimeError: please use Chrome in async with context
Exception ignored in: <function Daemon.del at 0x0000020790AFFE50>
Traceback (most recent call last):
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 144, in del
self.stop()
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 133, in stop
if self.running:
File "K:\python-works\ichrometesting\venv\lib\site-packages\ichrome\debugger.py", line 68, in getattr
value = getattr(self._self, name)
AttributeError: 'AsyncChromeDaemon' object has no attribute 'running'`

how to send a keyborad event ENTER,I didn't find any examples.

await tab.keyboard_send(key='ENTER')
{'id': 12, 'result': {}}
await tab.keyboard_send(string='ENTER')
{'id': 17, 'result': {}}
await tab.keyboard_send(key='ENTER')
{'id': 18, 'result': {}}
await tab.keyboard_send(key='ENTER')
{'id': 19, 'result': {}}
await tab.keyboard_send(key='BACK')
{'id': 20, 'result': {}}
await tab.keyboard_send(key='ESPACE')
{'id': 21, 'result': {}}
await tab.keyboard_send(key='ESPACE')
{'id': 22, 'result': {}}
await tab.js('zl_tz(8906)')
{'type': 'undefined'}
none of theses can use.

sync querySelectorAll

browser = Chrome(host="127.0.0.1", port=9222, timeout=3, retry=1)
tab = self.br.tabs[0]
tab.set_url('https://bing.com', timeout=5)
import time
time.sleep(3)
sel = tab.querySelectorAll('#sb_form_q')
INFO  2021-10-09 21:27:08 [ichrome] sync_utils.py(247): <Tab(chrome://newtab/)> send: {'method': 'Page.navigate', 'params': {'url': 'https://bing.com'}, 'id': 1}
INFO  2021-10-09 21:27:18 [ichrome] sync_utils.py(489): querySelectorAll crashed for: TypeError('the JSON object must be str, bytes or bytearray, not FailureException'), response: FailureException: TimeoutError()
 
File "/home/j/.local/lib/python3.9/site-packages/ichrome/sync_utils.py", line 492, in querySelectorAll
    raise error
  File "/home/j/.local/lib/python3.9/site-packages/ichrome/sync_utils.py", line 478, in querySelectorAll
    response = json.loads(response)["result"]["result"]["value"]
  File "/usr/lib/python3.9/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not FailureException

how to upload files?

if on selenium use send_keys,
Has anyone ever used this Ichrome successfully?

Exceptions while running example code

INFO  2021-08-09 20:25:52 [ichrome] pool.py(463): [enqueue](0) ChromeTask(<9234>, PENDING, id=1, tab=None), timeout=None, data=<ichrome.pool._TabWorker object at 0x7fb32a38a820>
INFO  2021-08-09 20:25:53 [ichrome] pool.py(171): [online] ChromeWorker(<9234>, 0/5, 0 todos) is online.
INFO  2021-08-09 20:25:53 [ichrome] pool.py(199): ChromeWorker(<9234>, 0/5, 0 todos) get a new task ChromeTask(<9234>, PENDING, id=1, tab=None).
PyPI · The Python Package Index
INFO  2021-08-09 20:25:58 [ichrome] pool.py(181): [offline] ChromeWorker(<9234>, 0/5, 0 todos) is offline.
INFO  2021-08-09 20:25:58 [ichrome] pool.py(240): [finished](0) ChromeTask(<9234>, PENDING, id=1, tab=None)
Traceback (most recent call last):
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/zphz/.vscode/extensions/ms-python.python-2021.8.1105858891/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/Users/zphz/.vscode/extensions/ms-python.python-2021.8.1105858891/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
    run()
  File "/Users/zphz/.vscode/extensions/ms-python.python-2021.8.1105858891/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/zphz/workspace/expert-monitor/pipeline/batch.py", line 21, in <module>
    test_chrome_engine_connect_tab()
  File "/Users/zphz/workspace/expert-monitor/pipeline/batch.py", line 16, in test_chrome_engine_connect_tab
    asyncio.get_event_loop().run_until_complete(
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/Users/zphz/workspace/expert-monitor/pipeline/batch.py", line 14, in _test_chrome_engine_connect_tab
    print(await tab.title)
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py", line 382, in __aexit__
    return await self.shutdown()
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py", line 375, in shutdown
    await worker.shutdown()
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py", line 273, in shutdown
    await self.daemon_task
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py", line 181, in _start_chrome_daemon
    logger.info(f'[offline] {self} is offline.')
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/daemon.py", line 827, in __aexit__
    await self.shutdown('__aexit__')
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/daemon.py", line 848, in shutdown
    await async_run(self.kill, True)
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/base.py", line 347, in function
    return func(*args, **kwargs)
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/daemon.py", line 563, in kill
    self.clear_chrome_process(self.port, max_deaths=max_deaths)
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/daemon.py", line 605, in clear_chrome_process
    return clear_chrome_process(port=port,
  File "/Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/base.py", line 124, in clear_chrome_process
    for proc in procs:
TypeError: 'NoneType' object is not iterable
Task was destroyed but it is pending!
task: <Task pending name='Task-7' coro=<ChromeWorker.future_consumer() running at /Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py:198> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fb32a3c9ca0>()]>>
Task was destroyed but it is pending!
task: <Task pending name='Task-6' coro=<ChromeWorker.future_consumer() running at /Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py:198> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fb32a3c9c70>()]>>
Task was destroyed but it is pending!
task: <Task pending name='Task-5' coro=<ChromeWorker.future_consumer() running at /Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py:198> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fb32a3c9c40>()]>>
Task was destroyed but it is pending!
task: <Task pending name='Task-4' coro=<ChromeWorker.future_consumer() running at /Users/zphz/opt/anaconda3/envs/pachytest-scraper/lib/python3.8/site-packages/ichrome/pool.py:198> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fb32a415d00>()]>>

Btw I'm using the following code to get results, am I doing right?

import asyncio

from ichrome.pool import ChromeEngine


def test_chrome_engine_connect_tab():

    async def _test_chrome_engine_connect_tab():

        async with ChromeEngine(port=9234, headless=True,
                                disable_image=True) as ce:
            async with ce.connect_tab(port=9234) as tab:
                await tab.goto('http://pypi.org')
                title = await tab.title
                return title

    loop = asyncio.get_event_loop()
    get_future = asyncio.ensure_future(_test_chrome_engine_connect_tab())
    loop.run_until_complete(get_future)
    return get_future.result()


if __name__ == "__main__":
    title = test_chrome_engine_connect_tab()
    print(title)

How could I get the value of array?

I used through ichrome to get a array, want its value.
But I always got {'type': 'object', 'subtype': 'array', 'className': 'Array', 'description': 'Array(5)', 'objectId': '6658223733079180638.11.1'}
How could I get the value of array inside?

Timeout Exception issues with Tab's

Experiencing Timeout Exception issues with Tab's

Happens whilst running your example (as per below) and waiting more than 5 seconds to accept
the alert

Suggest adding websocket._exceptions.WebSocketTimeoutException to the 'try/except' in Tab._recv_daemon

websocket._exceptions.WebSocketConnectionClosedException,

TERMINAL/LOG OUTPUT

2020-02-16 18:53:54 {INFO } [ichrome] sync_utils.py(86): new tab Tab(https://pypi.org/)
2020-02-16 18:53:54 {INFO } [ichrome] sync_utils.py(246): <Tab(https://pypi.org/)> send: {'method': 'Page.enable', 'params': {}, 'id': 1}
2020-02-16 18:53:57 {INFO } [ichrome] sync_utils.py(246): <Tab(https://pypi.org/)> send: {'method': 'Runtime.evaluate', 'params': {'expression': 'alert("test ok")'}, 'id': 2}
2020-02-16 18:54:02 {INFO } [ichrome] sync_utils.py(246): <Tab(https://pypi.org/)> send: {'method': 'Page.close', 'params': {}, 'id': 3}
Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Users\BSFau\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_socket.py", line 102, in recv
    bytes_ = _recv()
  File "C:\Users\BSFau\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_socket.py", line 84, in _recv
    return sock.recv(bufsize)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\ichrome\sync_utils.py", line 215, in _recv_daemon
    data_str = self.ws.recv()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_core.py", line 314, in recv
    opcode, data = self.recv_data()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_core.py", line 331, in recv_data
    opcode, frame = self.recv_data_frame(control_frame)
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_core.py", line 344, in recv_data_frame
    frame = self.recv_frame()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_core.py", line 378, in recv_frame
    return self.frame_buffer.recv_frame()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_abnf.py", line 361, in recv_frame
    self.recv_header()
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_abnf.py", line 309, in recv_header
    header = self.recv_strict(2)
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_abnf.py", line 396, in recv_strict
    bytes_ = self.recv(min(16384, shortage))
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_core.py", line 453, in _recv
    return recv(self.sock, bufsize)
  File "C:\Users\<USER>\Anaconda3\envs\<ENV>\lib\site-packages\websocket\_socket.py", line 105, in recv
    raise WebSocketTimeoutException(message)
websocket._exceptions.WebSocketTimeoutException: timed out

2020-02-16 18:54:18 {INFO } [ichrome] daemon.py(308): ChromeDaemon(127.0.0.1:9222) shutting down, start-up: 2020-02-16 17:53:51, duration: 27 seconds 3 ms.
2020-02-16 18:54:18 {INFO } [ichrome] daemon.py(247): ChromeDaemon(127.0.0.1:9222) daemon break after shutdown(2020-02-16 17:54:18).
2020-02-16 18:54:18 {INFO } [ichrome] daemon.py(264): ChromeDaemon(127.0.0.1:9222) daemon exited.

EXAMPLE

from ichrome import ChromeDaemon, Chrome


def main():
    with ChromeDaemon() as chromed:
        # run_forever means auto_restart
        chromed.run_forever(0)
        chrome = Chrome()
        tab = chrome.new_tab(url="https://pypi.org")
        tab.wait_loading(3)
        tab.js('alert("test ok")')
        tab.close()


if __name__ == "__main__":
    main()

Environment:

Python 3.7.6 in a conda virtualenv
Windows 10 x64
platform : win-64
user-agent : conda/4.7.10 requests/2.22.0 CPython/3.6.9 Windows/10 Windows/10.0.18362
ichrome 0.2.6 pypi_0 pypi
websocket-client 0.57.0 pypi_0 pypi

not accepting proxies from zyte because ichrome not taking 'verify' kwarg

hello i tried to use zyte proxy but its not working because they use ca cert to auth their proxy which ichrome doesnt support

in request module its 'verify' kwargs
example
import requests

response = requests.get(
    "https://httpbin.org/get",
    proxies={
        "http": "http://1kksksskskosmimiq:@proxy.crawlera.com:8011/",
        "https": "http://1kksksskskosmimiq:@proxy.crawlera.com:8011/",
    },
    verify='/path/to/zyte-proxy-ca.crt' 
)
print(response.text)

but ichrome do not have 'verify'

Use of "new_tab" and Chromium in Kiosh mode ...

If I use Chromium in Kiosh mode after use "tab = chrome.new_tab()" the Kiosh mode is lost and browser returns with the conventional layout.

You can try your "examples_sync.py" and add "--kiosh" as "extra_config: ["--kiosh"].

After "tab = chrome.new_tab()" the "kiosh" is lost.

Any solution ?

Install Chrome / Chromium shell

chromium centos

sudo yum -y install libX11 libXcomposite libXcursor libXdamage libXext libXi libXtst cups-libs libXScrnSaver libXrandr alsa-lib pango atk at-spi2-atk gtk3
https://github.com/scheib/chromium-latest-linux/blob/master/update.sh

chrome centos

echo -e "[google-chrome]\nname=google-chrome\nbaseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64\nenabled=1\ngpgcheck=1\ngpgkey=https://dl.google.com/linux/linux_signing_key.pub" > google-chrome.repo && sudo mv -f google-chrome.repo /etc/yum.repos.d/&&sudo yum -y install google-chrome-stable && google-chrome-stable --version

python3.8 centos

sudo yum update -y;sudo yum -y install git gcc openssl-devel bzip2-devel libffi-devel tmux htop&&sudo yum -y groupinstall "Development Tools"&& sudo yum -y install openssl-devel bzip2-devel libffi-devel python3-devel&&cd ~/&&curl -O https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz&&tar xvf Python-3.8.3.tgz&&cd Python-3.8*/&&sudo ./configure --prefix=/usr/local/python3.8&&sudo make&&sudo make install&&sudo rm -rf /usr/bin/python3&&sudo ln -s /usr/local/python3.8/bin/python3 /usr/bin/python3.8&&sudo ln -s /usr/local/python3.8/bin/python3 /usr/bin/python3&&python3 -V

sync onload

Why add_js_onload is async only? Is there way to do it in sync tab?

tab.querySelectorAll() 似乎有个小问题

该方法的index参数,会通过方法内部的javascript代码模板嵌入,并且在执行过程中,忽略掉非index指定的项目,比如指定取第0个索引号的项目,那么非0索引的项目都被忽略了;
然后,从javascript代码出来后,

if isinstance(index, int):
    if result:
        return result[index]  # 这一个地方,如果index >= 0,那么result应该只有一项才对
    else:
        return TagNotFound()
else:
    return result

使用了这个判断,如果index非0,那会不会引起序号超标?

Improved the REPL mode.

When I press the Arrow keys in REPL mode, the output is garbled.
Could you improve that ? like chrome-remote-interface, a javascript project.

incognito模式打开多个tab时无法正常使用

总是会先打开一个无痕窗口后,紧接着打开两个非无痕的窗口,是我使用方式不对吗?希望得到您的答复
运行环境:windows10,python3.8, ichrome =2.8.2,asyncio = 3.4.3

`import asyncio
from ichrome.pool import ChromeEngine
from inspect import getsource

async def tab_callback(self, tab, url, timeout):
await tab.set_url(url, timeout=50)
await tab.wait_loading(15)
await asyncio.sleep(20)
print(await tab.get_cookies())
return await tab.get_cookies()

async def main():
# AsyncChromeDaemon.DEFAULT_EXTRA_CONFIG.append("--incognito")
async with ChromeEngine(max_concurrent_tabs=5,
clear_after_shutdown=True,
# headless=False,
headless=True,
# disable_image=True,
extra_config=["--incognito"],
disable_image=False,
user_data_dir='./ichrome_user_data',
proxy=get_proxy()["http"].split("//")[1]) as ce:
tasks=[]
for i in range(2):
tasks.append(asyncio.ensure_future(ce.do('http://epub.cnipa.gov.cn/', getsource(tab_callback), timeout=50)))

    for task in tasks:
        result = await task
        print(result)
        assert result

# asyncio.run will raise aiohttp issue: https://github.com/aio-libs/aiohttp/issues/4324
# asyncio.get_event_loop().run_until_complete(main())

if name == "main":
asyncio.get_event_loop().run_until_complete(main())`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.