pageexplainer
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v3View latest version
This Val allows you to analyze webpages and answer questions about them based on their HTML, CSS, and JavaScript content.
- Fetches the source of any webpage
- Extracts HTML, CSS, and JavaScript content
- Uses OpenAI to analyze the page and answer questions about it
- Handles both inline and external stylesheets
Send a POST request to this Val with the following JSON body:
{ "url": "https://example.com", "question": "What is the main heading on this page?" }
curl -X POST https://api.val.town/v1/run/yourusername/webpage-analyzer \ -H "Content-Type: application/json" \ -d '{"url": "https://example.com", "question": "What is the main heading on this page?"}'
const response = await fetch('https://api.val.town/v1/run/yourusername/webpage-analyzer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: 'https://example.com',
question: 'What is the main heading on this page?'
}),
});
const data = await response.json();
console.log(data.answer);
The Val returns a JSON response with the following structure:
{ "url": "https://example.com", "question": "What is the main heading on this page?", "answer": "The main heading on the page is 'Example Domain'." }
- The Val truncates very large HTML, CSS, or JavaScript content to avoid exceeding token limits
- JavaScript evaluation is limited to static analysis (the Val cannot execute JavaScript)
- External resources like images, videos, or dynamically loaded content may not be fully analyzed
- The analysis depends on the capabilities of the OpenAI model being used
This Val requires an OpenAI API key to be set as an environment variable in your Val Town account.