This PHP class simulates being a web browser. It can post forms, read links, spoof referrers (helpful for accessing hotlink protected content), and a hell of alot more.
Some features:
- easily fetch the contents of a web page
- easily fetch the text from a web page (strip html tags)
- easily fetch the the links from a web page
- supports proxy hosts
- supports basic user/pass authentication
- supports setting user_agent, referer, cookies and header content
- supports browser redirects, and controlled depth of redirects
- expands fetched links to fully qualified URLs (default)
- easily submit form data and retrieve the results
- supports following html frames (added v0.92)
- supports passing cookies on redirects (added v0.92)
Insert First (Initialize):
-
<?
-
// creates the snoopy class object
-
// http://thedevnet.com/php/classes/snoopy-php-net-client/
-
-
include "Snoopy.class.php";
-
$snoopy = new Snoopy;
-
?>
Example (fetch a web page and display the return headers and content):
-
<?
-
// remember to already have the class included and object created
-
$snoopy->user = "joe";
-
$snoopy->pass = "bloe";
-
-
if($snoopy->fetch("http://www.slashdot.org/"))
-
{
-
echo "response code: ".$snoopy->response_code."<br>\n";
-
while(list($key,$val) = each($snoopy->headers))
-
echo $key.": ".$val."<br>\n";
-
echo "<p>\n";
-
-
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
-
}
-
else
-
echo "error fetching document: ".$snoopy->error."\n";
-
?>
Example (submit a form and print out the result headers and content):
-
<?
-
// remember to already have the class included and object created
-
$submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
-
-
$submit_vars["q"] = "amiga";
-
$submit_vars["submit"] = "Search!";
-
$submit_vars["searchhost"] = "Altavista";
-
-
-
if($snoopy->submit($submit_url,$submit_vars))
-
{
-
while(list($key,$val) = each($snoopy->headers))
-
echo $key.": ".$val."<br>\n";
-
echo "<p>\n";
-
-
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
-
}
-
else
-
echo "error fetching document: ".$snoopy->error."\n";
-
?>
Example (functionality):
-
<?
-
// remember to already have the class included and object created
-
$snoopy->proxy_host = "my.proxy.host";
-
$snoopy->proxy_port = "8080";
-
-
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
-
$snoopy->referer = "http://www.microsnot.com/";
-
-
$snoopy->cookies["SessionID"] = 238472834723489l;
-
$snoopy->cookies["favoriteColor"] = "RED";
-
-
$snoopy->rawheaders["Pragma"] = "no-cache";
-
-
$snoopy->maxredirs = 2;
-
$snoopy->offsiteok = false;
-
$snoopy->expandlinks = false;
-
-
$snoopy->user = "joe";
-
$snoopy->pass = "bloe";
-
-
if($snoopy->fetchtext("http://www.phpbuilder.com"))
-
{
-
while(list($key,$val) = each($snoopy->headers))
-
echo $key.": ".$val."<br>\n";
-
echo "<p>\n";
-
-
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
-
}
-
else
-
echo "error fetching document: ".$snoopy->error."\n";
-
?>
Example (framed content):
-
<?
-
// remember to already have the class included and object created
-
$snoopy->maxframes = 5;
-
-
if($snoopy->fetch("http://www.ispi.net/"))
-
{
-
echo "<PRE>".htmlspecialchars($snoopy->results[0])."</PRE>\n";
-
echo "<PRE>".htmlspecialchars($snoopy->results[1])."</PRE>\n";
-
echo "<PRE>".htmlspecialchars($snoopy->results[2])."</PRE>\n";
-
}
-
else
-
echo "error fetching document: ".$snoopy->error."\n";
-
?>
What is Snoopy?
Snoopy is a PHP class that simulates a web browser. It automates the
task of retrieving web page content and posting forms, for example.
Some of Snoopy\\\’s features:
* easily fetch the contents of a web page
* easily fetch the text from a web page (strip html tags)
* easily fetch the the links from a web page
* supports proxy hosts
* supports basic user/pass authentication
* supports setting user_agent, referer, cookies and header content
* supports browser redirects, and controlled depth of redirects
* expands fetched links to fully qualified URLs (default)
* easily submit form data and retrieve the results
* supports following html frames (added v0.92)
* supports passing cookies on redirects (added v0.92)
| Platforms: |
Web Based |
| Category: |
classes |
| License: |
GNU Lesser General Public License |
| Date: |
October 17, 2009 |
GD Star Rating
loading...
Originally posted 2009-10-17 21:44:26.
Popularity: 49%
Posted by irbobo @ 5 March 2010