File size: 614 Bytes
0078c1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from ddgs import DDGS


def web_fetch(url: str, format: str = "text_markdown") -> str:
    """Fetch a URL and extract its content.

    Args:
        url: The URL to visit and extract content from
        format: Output format: "text_markdown", "text_plain", "text_rich", "text" (raw HTML), "content" (raw bytes).

    Returns:
        Extracted content from the page
    """
    try:
        with DDGS() as ddgs:
            result = ddgs.extract(url, fmt=format)
            content = result.get("content", "")
            return content
    except Exception as e:
        return f"Error visiting URL: {str(e)}"