Update playwright/README.md
This commit is contained in:
@@ -5,14 +5,12 @@ Linux (WSL Debian)
|
|||||||
pip install playwright
|
pip install playwright
|
||||||
playwright install --with-deps
|
playwright install --with-deps
|
||||||
"""
|
"""
|
||||||
def Page():
|
|
||||||
def sync(func):
|
def sync(func):
|
||||||
import asyncio, threading, queue, functools; asyncio.set_event_loop_policy(None)
|
import asyncio, threading, queue, functools; asyncio.set_event_loop_policy(None)
|
||||||
def server():
|
def server(): sync.q.get(); f, a, kw = sync.obj; sync.obj = f(*a, **kw); sync.q.task_done(); server()
|
||||||
while sync.q.get(): f, a, kw = sync.obj; sync.obj = f(*a, **kw); sync.q.task_done()
|
|
||||||
if not hasattr(sync, 'q'): sync.q = queue.Queue(); threading.Thread(target=server).start()
|
if not hasattr(sync, 'q'): sync.q = queue.Queue(); threading.Thread(target=server).start()
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*a, **kw): sync.obj = func, a, kw; sync.q.put(True); sync.q.join(); return sync.obj
|
def wrapper(*a, **kw): sync.obj = func, a, kw; sync.q.put(1); sync.q.join(); return sync.obj
|
||||||
return wrapper
|
return wrapper
|
||||||
@sync
|
@sync
|
||||||
def Page():
|
def Page():
|
||||||
@@ -22,7 +20,6 @@ def Page():
|
|||||||
if attr[0] != '_' and callable(method := getattr(page, attr)): setattr(page, attr, sync(method))
|
if attr[0] != '_' and callable(method := getattr(page, attr)): setattr(page, attr, sync(method))
|
||||||
page._repr_png_ = page.screenshot
|
page._repr_png_ = page.screenshot
|
||||||
return page
|
return page
|
||||||
return Page()
|
|
||||||
(page := Page()).goto('https://example.org')
|
(page := Page()).goto('https://example.org')
|
||||||
print(page.title()) # Example Domain
|
print(page.title()) # Example Domain
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user