examples/markdownify/readme.md
This example demonstrates how to use the Markdownify graph to convert HTML content to Markdown format.
from scrapegraphai import Client
from scrapegraphai.logger import sgai_logger
# Set up logging
sgai_logger.set_logging(level="INFO")
# Initialize the client
sgai_client = Client(api_key="your-api-key")
# Example 1: Convert a website to Markdown
response = sgai_client.markdownify(
website_url="https://example.com"
)
print(response.markdown)
# Example 2: Convert HTML content directly
html_content = """
<div>
<h1>Hello World</h1>
<p>This is a <strong>test</strong> paragraph.</p>
</div>
"""
response = sgai_client.markdownify(
html_content=html_content
)
print(response.markdown)
The markdownify method accepts the following parameters:
website_url (str, optional): The URL of the website to convert to Markdownhtml_content (str, optional): Direct HTML content to convert to MarkdownNote: You must provide either website_url or html_content, but not both.
The response object contains:
markdown (str): The converted Markdown contentmetadata (dict): Additional information about the conversion processThe graph handles various edge cases:
If an error occurs, it will be logged and raised with appropriate error messages.