Skip to content

Instantly share code, notes, and snippets.

@queencitycyber
Created July 11, 2023 14:06
Show Gist options
  • Save queencitycyber/89e5c16750d91eda8f8a32d39607cfc4 to your computer and use it in GitHub Desktop.
Save queencitycyber/89e5c16750d91eda8f8a32d39607cfc4 to your computer and use it in GitHub Desktop.
URL -> Markdown
### Turn HTML page into Markdown (.md)
import requests
import html2text
def download_html(url):
response = requests.get(url)
return response.text
def convert_to_markdown(html):
converter = html2text.HTML2Text()
converter.body_width = 0 # Disable line wrapping
markdown = converter.handle(html)
return markdown
# Example usage
url = "YOUR URL"
html = download_html(url)
markdown = convert_to_markdown(html)
print(markdown)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment