Skip to content

Commit cec52e8

Browse files
committed
nbdev3
1 parent 2b16049 commit cec52e8

5 files changed

Lines changed: 58 additions & 112 deletions

File tree

index.ipynb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5+
"id": "b9abc78e",
56
"metadata": {},
67
"source": [
78
"# PlaywrightNB\n",
@@ -11,20 +12,23 @@
1112
},
1213
{
1314
"cell_type": "markdown",
15+
"id": "d5d27c1c",
1416
"metadata": {},
1517
"source": [
1618
"`PlaywrightNB` provides some little quality-of-life helpers for interactive use of the wonderful [Playwright](https://playwright.dev/python/) library. It's likely to be particularly of interest to folks using Jupyter."
1719
]
1820
},
1921
{
2022
"cell_type": "markdown",
23+
"id": "0377fe14",
2124
"metadata": {},
2225
"source": [
2326
"## Install"
2427
]
2528
},
2629
{
2730
"cell_type": "markdown",
31+
"id": "a09b5d72",
2832
"metadata": {},
2933
"source": [
3034
"```\n",
@@ -34,6 +38,7 @@
3438
},
3539
{
3640
"cell_type": "markdown",
41+
"id": "ca411f8a",
3742
"metadata": {},
3843
"source": [
3944
"## Overview"
@@ -42,6 +47,7 @@
4247
{
4348
"cell_type": "code",
4449
"execution_count": null,
50+
"id": "e25bc855",
4551
"metadata": {},
4652
"outputs": [],
4753
"source": [
@@ -51,6 +57,7 @@
5157
},
5258
{
5359
"cell_type": "markdown",
60+
"id": "e9cf8278",
5461
"metadata": {},
5562
"source": [
5663
"`playwrightnb` provide two main functions: `read_page_async(url)`, and `read_page(url)`. They are identical except the 1st is async.\n",
@@ -63,6 +70,7 @@
6370
{
6471
"cell_type": "code",
6572
"execution_count": null,
73+
"id": "fb247968",
6674
"metadata": {},
6775
"outputs": [],
6876
"source": [
@@ -72,6 +80,7 @@
7280
},
7381
{
7482
"cell_type": "markdown",
83+
"id": "c0ca0667",
7584
"metadata": {},
7685
"source": [
7786
"Use `h2md` to convert the HTML to markdown:"
@@ -80,6 +89,7 @@
8089
{
8190
"cell_type": "code",
8291
"execution_count": null,
92+
"id": "9f85abbe",
8393
"metadata": {},
8494
"outputs": [
8595
{
@@ -100,6 +110,7 @@
100110
},
101111
{
102112
"cell_type": "markdown",
113+
"id": "20a86a0e",
103114
"metadata": {},
104115
"source": [
105116
"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:"
@@ -108,6 +119,7 @@
108119
{
109120
"cell_type": "code",
110121
"execution_count": null,
122+
"id": "6c468fca",
111123
"metadata": {},
112124
"outputs": [],
113125
"source": [
@@ -119,6 +131,7 @@
119131
{
120132
"cell_type": "code",
121133
"execution_count": null,
134+
"id": "a2567e8e",
122135
"metadata": {},
123136
"outputs": [
124137
{
@@ -141,13 +154,15 @@
141154
},
142155
{
143156
"cell_type": "markdown",
157+
"id": "2a766a9a",
144158
"metadata": {},
145159
"source": [
146160
"If you don't need JS-rendering or other fanciness, use `get2md` instead, which uses `httpx.get` instead of playwright."
147161
]
148162
},
149163
{
150164
"cell_type": "markdown",
165+
"id": "f0eebcda",
151166
"metadata": {},
152167
"source": [
153168
"## fin -"
@@ -156,6 +171,7 @@
156171
{
157172
"cell_type": "code",
158173
"execution_count": null,
174+
"id": "017f1b69",
159175
"metadata": {},
160176
"outputs": [],
161177
"source": []
@@ -169,5 +185,5 @@
169185
}
170186
},
171187
"nbformat": 4,
172-
"nbformat_minor": 4
188+
"nbformat_minor": 5
173189
}

playwrightnb/core.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
# AUTOGENERATED! DO NOT EDIT! File to edit: ../00_core.ipynb.
44

5-
# %% auto 0
5+
# %% auto #0
66
__all__ = ['get_page', 'page_ready', 'frames_ready', 'wait_page', 'get_full_content', 'read_page_async', 'read_page', 'h2md',
77
'url2md_async', 'url2md', 'get2md']
88

9-
# %% ../00_core.ipynb
9+
# %% ../00_core.ipynb #5c4a0708
1010
from fastcore.utils import *
1111
from fastcore.meta import delegates
1212
import uuid, warnings
@@ -19,7 +19,7 @@
1919
from bs4 import BeautifulSoup, GuessedAtParserWarning
2020
from html2text import HTML2Text
2121

22-
# %% ../00_core.ipynb
22+
# %% ../00_core.ipynb #572ae069
2323
async def get_page(*args, stealth=False, **kwargs):
2424
p = await async_playwright().start()
2525
c = await p.chromium.launch(*args, **kwargs)
@@ -29,7 +29,7 @@ async def get_page(*args, stealth=False, **kwargs):
2929
if stealth: await stealth_async(page)
3030
return page
3131

32-
# %% ../00_core.ipynb
32+
# %% ../00_core.ipynb #b3f6649f
3333
async def page_ready(page, pause=50, timeout=5000):
3434
"Waith until main content of `page` is ready"
3535
await page.wait_for_load_state('domcontentloaded')
@@ -39,7 +39,7 @@ async def page_ready(page, pause=50, timeout=5000):
3939
except PTimeoutError as e: pass
4040
await page.wait_for_timeout(pause)
4141

42-
# %% ../00_core.ipynb
42+
# %% ../00_core.ipynb #132f0754
4343
async def frames_ready(page, pause=50, timeout=5000):
4444
"Wait until all visible frames (if any) on `page` are ready"
4545
iframes = await page.query_selector_all('iframe:visible')
@@ -52,13 +52,13 @@ async def frames_ready(page, pause=50, timeout=5000):
5252
await frame.wait_for_load_state('domcontentloaded', timeout=timeout)
5353
await frame.wait_for_load_state('networkidle', timeout=timeout)
5454

55-
# %% ../00_core.ipynb
55+
# %% ../00_core.ipynb #5a9ea7ab
5656
async def wait_page(page, pause=50, timeout=5000):
5757
"Wait until page and visible frames (if any) on `page` are ready"
5858
await page_ready(page, pause=pause, timeout=timeout)
5959
await frames_ready(page, pause=pause, timeout=timeout)
6060

61-
# %% ../00_core.ipynb
61+
# %% ../00_core.ipynb #75092cd8
6262
async def get_full_content(page):
6363
"Tuple of page content and dict of frames' content"
6464
main_content = await page.content()
@@ -71,7 +71,7 @@ async def get_full_content(page):
7171
iframe_contents[key] = await frame.content()
7272
return main_content, iframe_contents
7373

74-
# %% ../00_core.ipynb
74+
# %% ../00_core.ipynb #2cf5603b
7575
async def read_page_async(url, pause=50, timeout=5000, stealth=False, page=None):
7676
"Return contents of `url` and its iframes using Playwright async"
7777
has_page = bool(page)
@@ -83,12 +83,12 @@ async def read_page_async(url, pause=50, timeout=5000, stealth=False, page=None)
8383
finally:
8484
if not has_page: await page.close()
8585

86-
# %% ../00_core.ipynb
86+
# %% ../00_core.ipynb #ec0d3b40
8787
def read_page(url, pause=50, timeout=5000, stealth=False, page=None):
8888
"Return contents of `url` and its iframes using Playwright"
8989
with from_thread.start_blocking_portal() as p: return p.call(read_page_async, url, pause, timeout, stealth, page)
9090

91-
# %% ../00_core.ipynb
91+
# %% ../00_core.ipynb #7f1b1068
9292
def h2md(h):
9393
"Convert HTML `h` to markdown using `HTML2Text"
9494
h2t = HTML2Text(bodywidth=5000)
@@ -97,7 +97,7 @@ def h2md(h):
9797
h2t.ignore_images = True
9898
return h2t.handle(str(h))
9999

100-
# %% ../00_core.ipynb
100+
# %% ../00_core.ipynb #879a818e
101101
async def url2md_async(url, sel=None, pause=50, timeout=5000, stealth=False, page=None):
102102
"Read `url` with `read_page`, optionally selecting CSS selector `sel`"
103103
warnings.filterwarnings("ignore", category=GuessedAtParserWarning)
@@ -106,7 +106,7 @@ async def url2md_async(url, sel=None, pause=50, timeout=5000, stealth=False, pag
106106
content = soup.select_one(sel)
107107
return h2md(content)
108108

109-
# %% ../00_core.ipynb
109+
# %% ../00_core.ipynb #a9c44a62
110110
def url2md(url, sel=None, pause=50, timeout=5000, stealth=False, page=None):
111111
"Read `url` with `read_page`"
112112
warnings.filterwarnings("ignore", category=GuessedAtParserWarning)
@@ -115,7 +115,7 @@ def url2md(url, sel=None, pause=50, timeout=5000, stealth=False, page=None):
115115
content = soup.select_one(sel)
116116
return h2md(content)
117117

118-
# %% ../00_core.ipynb
118+
# %% ../00_core.ipynb #9b2c101b
119119
@delegates(get)
120120
def get2md(url, sel=None, **kwargs):
121121
"Read `url` with `httpx.get`"

pyproject.toml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
[build-system]
2-
requires = ["setuptools>=64.0"]
2+
requires = ["setuptools>=64"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name="playwrightnb"
7+
dynamic = ["version"]
8+
description = "Helpers for using Playwright from notebooks and more"
9+
readme = "README.md"
710
requires-python=">=3.8"
8-
dynamic = [ "keywords", "description", "version", "dependencies", "optional-dependencies", "readme", "license", "authors", "classifiers", "entry-points", "scripts", "urls"]
11+
license = {text = "Apache-2.0"}
12+
authors = [{name = "Jeremy Howard", email = "info@fast.ai"}]
13+
keywords = ['nbdev', 'jupyter', 'notebook', 'python', 'playwright']
14+
classifiers = [
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3 :: Only",
17+
]
18+
dependencies = []
919

10-
[tool.uv]
11-
cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
20+
[project.urls]
21+
Repository = "https://github.com/AnswerDotAI/playwrightnb"
22+
Documentation = "https://AnswerDotAI.github.io/playwrightnb"
23+
24+
[project.entry-points.nbdev]
25+
playwrightnb = "playwrightnb._modidx:d"
26+
27+
[tool.setuptools.dynamic]
28+
version = {attr = "playwrightnb.__version__"}
29+
30+
[tool.setuptools.packages.find]
31+
include = ["playwrightnb"]
32+
33+
[tool.nbdev]
34+
nbs_path = '.'
35+
custom_sidebar = false

settings.ini

Lines changed: 0 additions & 37 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)