()
| 227 | |
| 228 | |
| 229 | def main(): |
| 230 | parser = argparse.ArgumentParser(description='Fetch web page content and convert to markdown') |
| 231 | parser.add_argument('url', help='URL to fetch') |
| 232 | parser.add_argument('--timeout', type=int, default=30, help='Request timeout in seconds (default: 30)') |
| 233 | parser.add_argument('--max-length', type=int, default=100000, help='Maximum output length (default: 100000)') |
| 234 | parser.add_argument('--raw', action='store_true', help='Output raw HTML instead of markdown') |
| 235 | |
| 236 | args = parser.parse_args() |
| 237 | |
| 238 | if args.raw: |
| 239 | if HAS_REQUESTS: |
| 240 | content = fetch_with_requests(args.url, timeout=args.timeout) |
| 241 | else: |
| 242 | content = fetch_with_urllib(args.url, timeout=args.timeout) |
| 243 | else: |
| 244 | content = fetch_url(args.url, timeout=args.timeout) |
| 245 | |
| 246 | # Truncate if too long |
| 247 | if len(content) > args.max_length: |
| 248 | content = content[:args.max_length] + "\n\n[Content truncated...]" |
| 249 | |
| 250 | print(content) |
| 251 | |
| 252 | |
| 253 | if __name__ == '__main__': |
no test coverage detected