8f3a28effb
* pythonExtension and python runtime improvements * Adding streaming support * Use writeFileSync * Restructure extension docs and add python extension docs * Fix broken link * Update docs/config/extensions/overview.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update docs/config/extensions/aptGet.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update docs/config/extensions/custom.mdx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Add environment variable support --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import html2text
|
|
import requests
|
|
import argparse
|
|
import sys
|
|
|
|
def fetch_html(url):
|
|
"""Fetch HTML content from a URL."""
|
|
try:
|
|
response = requests.get(url)
|
|
response.raise_for_status() # Raise an exception for HTTP errors
|
|
return response.text
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"Error fetching URL: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
# Set up command line argument parsing
|
|
parser = argparse.ArgumentParser(description='Convert HTML from a URL to plain text.')
|
|
parser.add_argument('url', help='The URL to fetch HTML from')
|
|
parser.add_argument('--ignore-links', action='store_true',
|
|
help='Ignore converting links from HTML')
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Fetch HTML from the URL
|
|
html_content = fetch_html(args.url)
|
|
|
|
# Configure html2text
|
|
h = html2text.HTML2Text()
|
|
h.ignore_links = args.ignore_links
|
|
|
|
# Convert HTML to text and print
|
|
text_content = h.handle(html_content)
|
|
print(text_content)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|