PHP Classes

File: browser.example.php

Recommend this page to a friend!
  Classes of Jon Gjengset   Browser   browser.example.php   Download  
File: browser.example.php
Role: Example script
Content type: text/plain
Description: An example of how the script can be used
Class: Browser
Retrieve Web pages emulating a browser
Author: By
Last change: Fixed Wikipedia 402 issue by adding user agent string
Date: 13 years ago
Size: 757 bytes
 

Contents

Class file image Download
<?php

require 'browser.class.php';

/**
 * The long way to the PHP Reference Manual...
 */

/**
 * New browser object
 * User agent string is not compulsory usually,
 * but Wikipedia sends us a 402 if we don't
 * Thanks Richard Williams
 */
$b = new Browser ( 'PHP Browser' );

/**
 * Navigate to the first url
 */
$b -> navigate ( 'http://en.wikipedia.org/wiki/Main_Page' );
/**
 * Search for php
 */
$b -> submitForm (
     
$b -> getForm ( "//form[@id='searchform']" )
          ->
setAttributeByName ( 'search', 'php' ),
     
'fulltext'
 
)
  ->
click ( "//a[@title='PHP']" ) // Click the PHP search result
 
-> click ( "PHP Reference Manual" ); // Click the link to the ref
echo $b -> getSource(); // Output the source