File tree Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change 3
3
4
4
5
5
class Browserbase :
6
- # Create new Browserbase instance
7
6
def __init__ (self , api_key : str ):
7
+ """Create new Browserbase instance"""
8
8
if not api_key :
9
9
raise ValueError ("Browserbase API key was not provided" )
10
10
11
11
self .api_key = api_key
12
12
13
- # Load a page in a headless browser and return the html contents
14
13
def load (self , url : str ):
14
+ """Load a page in a headless browser and return the html contents"""
15
15
if not url :
16
16
raise ValueError ("Page URL was not provided" )
17
17
@@ -26,8 +26,8 @@ def load(self, url: str):
26
26
27
27
return html
28
28
29
- # Load multiple pages in a headless browser and return the html contents
30
29
def load_urls (self , urls : List [str ]):
30
+ """Load multiple pages in a headless browser and return the html contents"""
31
31
if not urls :
32
32
raise ValueError ("Page URL was not provided" )
33
33
@@ -36,11 +36,9 @@ def load_urls(self, urls: List[str]):
36
36
"wss://api.browserbase.com?apiKey=" + self .api_key
37
37
)
38
38
39
- results = []
40
39
for url in urls :
41
40
page = browser .new_page ()
42
41
page .goto (url )
43
- results . append ( page .content () )
42
+ yield page .content ()
44
43
45
44
browser .close ()
46
- return results
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def test_load(self):
13
13
14
14
def test_load_urls (self ):
15
15
result = self .browserbase .load_urls (["https://example.com" ])
16
- self .assertIn ("Example Domain" , result [ 0 ] )
16
+ self .assertIn ("Example Domain" , next ( result ) )
17
17
18
18
19
19
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments