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.
webpage-analyzer.ts
https://neverstew--72a774c6345711f0a39d9e149126039e.web.val.run
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
- Provides a simple, user-friendly web interface
- Also supports JSON API for programmatic usage
Simply visit the Val URL in your browser to use the web interface:
- Enter a URL to analyze
- Type your question about the webpage
- Click "Analyze Webpage" to get your answer
You can also use this Val programmatically by sending a POST request with JSON:
{ "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 API 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.