PHP code example of north-foundry / voyager-page-map-php

1. Go to this page and download the library: Download north-foundry/voyager-page-map-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

north-foundry / voyager-page-map-php example snippets




orthFoundry\VoyagerPageMap\VoyagerPageMap;

$html = <<<'HTML'
<!doctype html>
<html lang="it">
<head>
    <title>Login</title>
</head>
<body>
    <main>
        <h1>Accedi</h1>
        <form aria-label="Login">
            <label for="email">Email</label>
            <input id="email" type="email" 

$pageContext = $pageMap->toText();

$prompt = <<<PROMPT
You are given a semantic map of a web page.

Identify the email field.
Return only its @e reference.

$pageContext
PROMPT;

// Pass $prompt to the LLM client or prompt pipeline of your choice.

$choice = '@e5';

$element = $pageMap->findByReference($choice);
$reference = $pageMap->ref($choice);

echo $element?->toText();
// @e5 input "Email" [type=email, 

use NorthFoundry\VoyagerPageMap\Configuration\VoyagerPageMapConfiguration;

$configuration = VoyagerPageMapConfiguration::agent()
    ->withRelativeUrlResolution()
    ->withAttributes(['id', 'data-tracking'])
    ->withIgnoredSelectors(['.cookie-banner', '[data-testid="advertisement"]']);

$pageMap = VoyagerPageMap::fromHtml(
    $html,
    baseUrl: 'https://example.com/login',
    configuration: $configuration,
);