Fetch content from a URL and return as markdown.
(url: str, timeout: int = 30)
| 210 | |
| 211 | |
| 212 | def fetch_url(url: str, timeout: int = 30) -> str: |
| 213 | """Fetch content from a URL and return as markdown.""" |
| 214 | if HAS_REQUESTS: |
| 215 | html_content = fetch_with_requests(url, timeout) |
| 216 | else: |
| 217 | html_content = fetch_with_urllib(url, timeout) |
| 218 | |
| 219 | # Check if it's an error message |
| 220 | if html_content.startswith("Error") or html_content.startswith("HTTP Error") or html_content.startswith("URL Error"): |
| 221 | return html_content |
| 222 | |
| 223 | # Convert to markdown |
| 224 | parser = HTMLToMarkdown() |
| 225 | parser.feed(html_content) |
| 226 | return parser.get_markdown() |
| 227 | |
| 228 | |
| 229 | def main(): |
no test coverage detected