Convert any webpage into LLM-ready Markdown using Gaffa
Prerequistes
python -m venv venv && source venv/bin/activatepip install requests openaiGAFFA_API_KEY=your_gaffa_api_key
OPENAI_API_KEY=your_openai_api_keyConvert a webpage to Markdown
import requests
import openai
GAFFA_API_KEY = os.getenv("GAFFA_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
# Fetch the markdown content from Gaffa
def fetch_markdown_with_gaffa(url):
payload = {
"url": url,
"proxy_location": None,
"async": False,
"max_cache_age": 0,
"settings": {
"record_request": False,
"actions": [
{
"type": "wait",
"selector": "article"
},
{
"type": "generate_markdown"
}
]
}
}
# Set the headers for the request
headers = {
"x-api-key": GAFFA_API_KEY,
"Content-Type": "application/json"
}
# Make the POST request to the Gaffa API
print("Calling Gaffa API to generate markdown...")
response = requests.post("https://api.gaffa.dev/v1/browser/requests", json=payload, headers=headers)
response.raise_for_status()
# Extract the markdown URL from the response
markdown_url = response.json()["data"]["actions"][1]["output"]
# Fetch the markdown content from the generated URL
print(f"📥 Fetching markdown from: {markdown_url}")
markdown_response = requests.get(markdown_url)
markdown_response.raise_for_status()
return markdown_response.textAsk questions using OpenAI
User Interaction and Execution
Full Script
Running the Script
Last updated