Skip to content

Commit a997753

Browse files
committed
v0.1.1
1 parent cc6d3aa commit a997753

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changelog
22

3-
## v0.1.0
3+
## v0.1.1
44

5-
- feat: new parameter to allow reusing an open browser.
5+
- adding browser to cast method too

src/webson/_webson.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ async def _get_contents_with_browser(self, url: str, browser: Browser) -> str:
163163
finally:
164164
await page.close()
165165

166-
def cast[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
166+
def cast[T: msgspec.Struct](
167+
self, url: str, *, to: type[T], browser: Browser | None = None
168+
) -> T:
167169
"""
168170
Synchronously casts a webpage's content into a structured output.
169171
@@ -185,9 +187,11 @@ def cast[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
185187
>>> data = webson.cast("https://example.com", to=PageData)
186188
>>> print(data.title)
187189
"""
188-
return run_sync(self.cast_async, url, to=to)
190+
return run_sync(self.cast_async, url, to=to, browser=browser)
189191

190-
async def cast_async[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
192+
async def cast_async[T: msgspec.Struct](
193+
self, url: str, *, to: type[T], browser: Browser | None = None
194+
) -> T:
191195
"""
192196
Asynchronously casts a webpage's content into a structured output.
193197
@@ -208,7 +212,7 @@ async def cast_async[T: msgspec.Struct](self, url: str, *, to: type[T]) -> T:
208212
>>> print(structured_data)
209213
"""
210214
# Retrieve the raw HTML page contents asynchronously.
211-
page_contents = await self.get_contents_async(url)
215+
page_contents = await self.get_contents_async(url, browser=browser)
212216

213217
# Convert the HTML to markdown for easier parsing.
214218
page_md = cast(str, md(page_contents))

0 commit comments

Comments
 (0)