@@ -11,57 +11,30 @@ def browser_base_fetch(api_key: str, project_id: str, link: List[str],
11
11
12
12
This module provides an interface to the BrowserBase API.
13
13
14
- The `browser_base_fetch` function takes three arguments:
15
- - `api_key`: The API key provided by BrowserBase.
16
- - `project_id`: The ID of the project on BrowserBase where you want to fetch data from.
17
- - `link`: The URL or link that you want to fetch data from.
18
- - `text_content`: A boolean flag to specify whether to return only the
19
- text content (True) or the full HTML (False).
20
- - `async_mode`: A boolean flag that determines whether the function runs asynchronously
21
- (True) or synchronously (False, default).
22
-
23
- It initializes a Browserbase object with the given API key and project ID,
24
- then uses this object to load the specified link.
25
- It returns the result of the loading operation.
26
-
27
- Example usage:
28
-
29
- ```
30
- from browser_base_fetch import browser_base_fetch
31
-
32
- result = browser_base_fetch(api_key="your_api_key",
33
- project_id="your_project_id", link="https://example.com")
34
- print(result)
35
- ```
36
-
37
- Please note that you need to replace "your_api_key" and "your_project_id"
38
- with your actual BrowserBase API key and project ID.
39
-
40
14
Args:
41
15
api_key (str): The API key provided by BrowserBase.
42
16
project_id (str): The ID of the project on BrowserBase where you want to fetch data from.
43
- link (str): The URL or link that you want to fetch data from.
44
- text_content (bool): Whether to return only the text content
45
- (True) or the full HTML (False). Defaults to True.
46
- async_mode (bool): Whether to run the function asynchronously
47
- (True) or synchronously (False). Defaults to False.
17
+ link (List[str]): The URLs or links that you want to fetch data from.
18
+ text_content (bool): Whether to return only the text content (True) or the full HTML (False).
19
+ async_mode (bool): Whether to run the function asynchronously (True) or synchronously (False).
48
20
49
21
Returns:
50
- object : The result of the loading operation .
22
+ List[str] : The results of the loading operations .
51
23
"""
52
-
53
24
try :
54
25
from browserbase import Browserbase
55
26
except ImportError :
56
- raise ImportError (f"""The browserbase module is not installed.
57
- Please install it using `pip install browserbase`.""" )
27
+ raise ImportError ("The browserbase module is not installed. Please install it using `pip install browserbase`." )
58
28
59
-
60
- browserbase = Browserbase (api_key = api_key , project_id = project_id )
29
+ # Initialize client with API key
30
+ browserbase = Browserbase (api_key = api_key )
31
+
32
+ # Create session with project ID
33
+ session = browserbase .sessions .create (project_id = project_id )
61
34
62
35
result = []
63
36
async def _async_fetch_link (l ):
64
- return await asyncio .to_thread (browserbase .load , l , text_content = text_content )
37
+ return await asyncio .to_thread (session .load , l , text_content = text_content )
65
38
66
39
if async_mode :
67
40
async def _async_browser_base_fetch ():
@@ -72,7 +45,6 @@ async def _async_browser_base_fetch():
72
45
result = asyncio .run (_async_browser_base_fetch ())
73
46
else :
74
47
for l in link :
75
- result .append (browserbase .load (l , text_content = text_content ))
76
-
48
+ result .append (session .load (l , text_content = text_content ))
77
49
78
50
return result
0 commit comments