This package extends HTTP_Client and provides a an API which represents a web browser interface.
For example, there are methods which represent the basic web browser buttons.
- go
- back
- goHome
- reload
This package also provides methods which are inspired by the Perl WWW::Mechanize module to provide an intuitive interface for writing programs which interact with websites.
- followLink
- selectForm
- submitForm
- getContent
There are also methods which provide a convenient way of analyzing and manipulating the content of web pages.
- contentContains
- contentMatches
- contentTags
- saveContent
- updateContent
Example program using HTTP_Browser:
<?php
include 'HTTP/Browser.php';
$q = 'HTTP_Request';
$config = array(
'agent_alias' => 'Windows IE 6',
'home_page' => 'http://pear.php.net/',
);
$browser = new HTTP_Browser( $config );
$form = array(
'method' => 'GET',
'action' => '/search.php',
'fields' => array(
'q' => $q,
'in' => 'packages',
),
);
$browser->submit( $form );
if ( $browser->success() ) {
$browser->followLink($q);
$regex
= '/'
. '<li>'
. '<a \s+ href=" [^"]+ ">'
. '( [^<]+ )'
. '<\/a> \s+ [\(] lead [\)]'
. '<\/li>'
. '/xms';
$developer_match = $browser->contentMatches( $regex );
echo "$q -- Lead Developer: ";
echo $developer_match[1][0];
echo "\n";
}
else {
echo $browser->getContent();
}
?>
Known shortcomings:
- back & reload won't resubmit a form
- clickButton is unimplemented
- ... surely more to come
|