Asynchronous Chrome DevTools Protocol Package for access lower level methods in Chrome.
To install aiochrome, simply:
$ python3 -m pip install -U git+https://github.com/anbuhckr/aiocdp.git
or from source:
$ python3 setup.py install
#! /usr/bin/env python3
import asyncio
from aiocdp.browser import Browser
async def request_will_be_sent(**kwargs):
print(f"loading: {kwargs.get('request').get('url')}")
async def main():
# chrome options
options = [
"--disable-gpu",
"--no-sandbox",
"--disable-setuid-sandbox",
]
# create browser instance with custom options
browser = Browser(opts=options)
# register callback if you want
browser.on('main', 'Network.requestWillBeSent', request_will_be_sent)
# start browser with custom method
try:
await browser.start()
await browser.send('Network.enable')
await browser.send('Page.enable')
await browser.send('Page.navigate', url="https://github.com/anbuhckr/aiocdp")
# wait for loading
await asyncio.sleep(10)
# handle exception
except Exception as e:
print(e)
pass
# close browser
await browser.stop()
if __name__ == '__main__':
asyncio.run(main())
more methods or events could be found in Chrome DevTools Protocol