MCPcopy
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / browser_base_fetch

Function browser_base_fetch

scrapegraphai/docloaders/browser_base.py:9–61  ·  view source on GitHub ↗

BrowserBase Fetch This module provides an interface to the BrowserBase API. Args: api_key (str): The API key provided by BrowserBase. project_id (str): The ID of the project on BrowserBase where you want to fetch data from. link (List[str]): The URLs or links t

(
    api_key: str,
    project_id: str,
    link: List[str],
    text_content: bool = True,
    async_mode: bool = False,
)

Source from the content-addressed store, hash-verified

7
8
9def browser_base_fetch(
10 api_key: str,
11 project_id: str,
12 link: List[str],
13 text_content: bool = True,
14 async_mode: bool = False,
15) -> List[str]:
16 """
17 BrowserBase Fetch
18
19 This module provides an interface to the BrowserBase API.
20
21 Args:
22 api_key (str): The API key provided by BrowserBase.
23 project_id (str): The ID of the project on BrowserBase where you want to fetch data from.
24 link (List[str]): The URLs or links that you want to fetch data from.
25 text_content (bool): Whether to return only the text content (True) or the full HTML (False).
26 async_mode (bool): Whether to run the function asynchronously (True) or synchronously (False).
27
28 Returns:
29 List[str]: The results of the loading operations.
30 """
31 try:
32 from browserbase import Browserbase
33 except ImportError:
34 raise ImportError(
35 "The browserbase module is not installed. Please install it using `pip install browserbase`."
36 )
37
38 # Initialize client with API key
39 browserbase = Browserbase(api_key=api_key)
40
41 # Create session with project ID
42 session = browserbase.sessions.create(project_id=project_id)
43
44 result = []
45
46 async def _async_fetch_link(url):
47 return await asyncio.to_thread(session.load, url, text_content=text_content)
48
49 if async_mode:
50
51 async def _async_browser_base_fetch():
52 for url in link:
53 result.append(await _async_fetch_link(url))
54 return result
55
56 result = asyncio.run(_async_browser_base_fetch())
57 else:
58 for url in link:
59 result.append(session.load(url, text_content=text_content))
60
61 return result

Callers 2

fetch_contentMethod · 0.85
handle_web_sourceMethod · 0.85

Calls 3

runMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected