Skip to content

Commit 3a59cbf

Browse files
committed
Python comments and generators
1 parent 5153363 commit 3a59cbf

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

‎browserbase/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44

55
class Browserbase:
6-
# Create new Browserbase instance
76
def __init__(self, api_key: str):
7+
"""Create new Browserbase instance"""
88
if not api_key:
99
raise ValueError("Browserbase API key was not provided")
1010

1111
self.api_key = api_key
1212

13-
# Load a page in a headless browser and return the html contents
1413
def load(self, url: str):
14+
"""Load a page in a headless browser and return the html contents"""
1515
if not url:
1616
raise ValueError("Page URL was not provided")
1717

@@ -26,8 +26,8 @@ def load(self, url: str):
2626

2727
return html
2828

29-
# Load multiple pages in a headless browser and return the html contents
3029
def load_urls(self, urls: List[str]):
30+
"""Load multiple pages in a headless browser and return the html contents"""
3131
if not urls:
3232
raise ValueError("Page URL was not provided")
3333

@@ -36,11 +36,9 @@ def load_urls(self, urls: List[str]):
3636
"wss://api.browserbase.com?apiKey=" + self.api_key
3737
)
3838

39-
results = []
4039
for url in urls:
4140
page = browser.new_page()
4241
page.goto(url)
43-
results.append(page.content())
42+
yield page.content()
4443

4544
browser.close()
46-
return results

‎tests/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_load(self):
1313

1414
def test_load_urls(self):
1515
result = self.browserbase.load_urls(["https://example.com"])
16-
self.assertIn("Example Domain", result[0])
16+
self.assertIn("Example Domain", next(result))
1717

1818

1919
if __name__ == "__main__":

0 commit comments

Comments
 (0)