Webpage Analyzer

This Val allows you to analyze webpages and answer questions about them based on their HTML, CSS, and JavaScript content.

Features

  • 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

Usage

Web Interface

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

API Usage

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?" }

Example using curl:

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?"}'

Example using JavaScript:

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);

Response Format (API)

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'." }

Limitations

  • 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

Requirements

This Val requires an OpenAI API key to be set as an environment variable in your Val Town account.