Helpers for using Playwright from notebooks and more
Project description
PlaywrightNB
PlaywrightNB
provides some little quality-of-life helpers for
interactive use of the wonderful
Playwright library. It’s likely to be
particularly of interest to folks using Jupyter.
Install
pip install playwrightnb
Overview
from playwrightnb import *
from html.parser import HTMLParser
playwrightnb
provide two main functions: read_page_async(url)
, and
read_page(url)
. They are identical except the 1st is async.
They return a tuple of the main HTML page contents, and a dict mapping
iframe IDs to their HTML contents. They handle Javascript and other
trickiness largely automatically, however you can pass a pause
parameter (in milliseconds) if you need to insert some manual waits. You
can also pass a timeout
(also in milliseconds).
For instance, the Dyalog APL help information is provided inside an iframe that’s dynamically loaded by JS, but we are able to read it directly:
sh_url = 'https://help.dyalog.com/19.0/#UserGuide/Installation%20and%20Configuration/Shell%20Scripts.htm'
cts,iframes = read_page(sh_url)
Use h2md
to convert the HTML to markdown:
print(h2md(iframes['topic'])[94:250])
## Shell Scripts
Shell scripts are typically executed from a terminal (or shell).
A script is executed by typing its name. User input is entered from the
In the case where you want to grab some particular element using a CSS
selector, use
url2md
to read the page, find the selector, and convert to markdown. E.g, for
accessing Discord’s JS-rendered docs:
url = 'https://discord.com/developers/docs/interactions/application-commands'
sel = '.page-content-scrolling-container'
md = url2md(url, sel)
print(md[856:1215])
Application commands are native ways to interact with apps in the Discord client. There are 3 types of commands accessible in different interfaces: the chat input, a message's context menu (top-right menu or right-clicking in a message), and a user's context menu (right-clicking on a user).
## Application Command Object
###### Application Command Naming
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file playwrightnb-0.2.1.tar.gz
.
File metadata
- Download URL: playwrightnb-0.2.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82b757ff8416866414cf8245ec313f85d65a0072975053556522634e648c18f3 |
|
MD5 | a6227438f525044c346871d28763c1e4 |
|
BLAKE2b-256 | 9b7a6069795302f6ca5ab0e60e2e6a8073bf3405f259d120e886bbfca02c3584 |
File details
Details for the file playwrightnb-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: playwrightnb-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 566b3b57719676d2b43a566dd316e2cfccb1cd2de46643a24259d5873d710c22 |
|
MD5 | 3466a307a5b3566304c887cc02d7b488 |
|
BLAKE2b-256 | 30cfcd768c542fc5e2fe677dbf594a64d4ef63d5d77dd2064a0ce92fa754de49 |