Snoopy's powerful PHP collection class USES instance code

  • 2020-03-31 21:24:46
  • OfStack

Download address: (link: #)

Some features of Snoopy:

Fetch the contents of a web page
Fetch the text content of a web page (HTML tags removed) fetchtext
Fetch a link to a web page, form fetchlinks fetchform
4 support proxy hosts
Basic username/password authentication is supported
6 support setting user_agent, referer, cookies and header content
Supports browser redirection and controls the depth of redirection
8. Ability to extend links in web pages to high quality urls (default)
Submit the data and get the return value
Support for tracking HTML frameworks
Supports cookies when redirecting
Requiring php4 above is fine because it's the best choice for PHP when a class doesn't need to be extended and the server doesn't support curl,

Methods:

The fetch ($URI)
-- �

This is the method used to crawl the contents of a web page.
The $URI parameter is the URL address of the fetched web page.
The result of the fetch is stored in $this-> In the results.
If you are fetching a frame, Snoopy will trace each frame into an array and then save $this-> The results.

Fetchtext ($URI)
-- -- -

This method is similar to fetch() except that it removes HTML tags and other irrelevant data and returns only the text in the page.

Fetchform ($URI)
-- -- -

This method is similar to fetch() except that it removes HTML tags and other irrelevant data and returns only the form content (form) in the page.

Fetchlinks ($URI)
-- -- -- -

This method is similar to fetch() except that it removes the HTML tags and other irrelevant data and returns only the links in the page.
By default, relative links are automatically completed and converted to the full URL.

Submit ($URI, $formvars)
-- -- -- -- -

This method sends a confirmation form to the link address specified by the $URL. $formvars is an array that stores form parameters.

Submittext ($URI, $formvars)
-- -- -- -- �

This method is similar to submit() except that it removes the HTML tags and other irrelevant data and returns only the text content of the page after login.

Submitlinks ($URI)
-- -- -- -

This method is similar to submit() except that it removes the HTML tag and other irrelevant data and returns only the link in the page.
By default, relative links are automatically completed and converted to the full URL.

Class properties: (default values in parentheses)

The host to which $host is connected
The port to which $port connects
The proxy host used by $proxy_host, if any
The proxy host port used by $proxy_port, if any
$agent user agent disguise (Snoopy v0.1)
$referer incoming information, if any
$cookies cookies, if any
$rawheanders other header information, if any
Maximum number of redirects, 0= not allowed (5)
$offsiteok been or not to allow redirects off - site. (true)
$expandlinks complete links to full address (true)
$user authenticates the user name, if any
$pass authenticates the user name, if any
Accept HTTP accept type (image/ GIF, image/x-xbitmap, image/jpeg, image/pjpeg, */*)
Where do I report an error, if any
Response_code the response code returned from the server
$headers the header information returned from the server
$maxlength returns the maximum data length
$read_timeout read operation timeout (requires PHP 4 Beta 4+)
Set to 0 to no timeout
$timed_out this property returns true (requires PHP 4 Beta 4+) if a read operation timed out
$maxframes allows the maximum number of frames to be traced
$status fetches the HTTP status
$temp_dir temporary file directory that web server can write to (/ TMP)
$curl_path cURL binary's directory, which is set to false if there is no cURL binary

The following is a demo
 
include "Snoopy.class.php"; 
$snoopy = new Snoopy; 
$snoopy->proxy_host = "//www.jb51.net"; 
$snoopy->proxy_port = "80"; 
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; 
$snoopy->referer = "//www.jb51.net"; 
$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("//www.jb51.net")) 
{ 
echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>n"; 
} 
else 
echo "error fetching document: ".$snoopy->error."n"; 

Here are some code snippets:
1, get the specified url content
 
<? 
$url = "//www.jb51.net"; 
include("snoopy.php"); 
$snoopy = new Snoopy; 
$snoopy->fetch($url); //Get everything
echo $snoopy->results; //According to the results
//Can choose the following
$snoopy->fetchtext //Get the text content (remove the HTML code)
$snoopy->fetchlinks //For a link
$snoopy->fetchform //Get the form
?> 

2 form submission
 
<?php 
$formvars["username"] = "admin"; 
$formvars["pwd"] = "admin"; 
$action = "//www.jb51.net";//</a> Form submission address  
$snoopy->submit($action,$formvars);//$formvars is an array of submissions
echo $snoopy->results; //Gets the result returned after the form is submitted
//Can choose the following
$snoopy->submittext; //Only HTML stripped text is returned after submission
$snoopy->submitlinks;//Only links are returned after submission
?> 

Now that we've submitted the form we can do a lot of things and now we're going to disguise the IP, disguise the browser
3 camouflage
 
<?php 
$formvars["username"] = "admin"; 
$formvars["pwd"] = "admin"; 
$action = "//www.jb51.net"; 
include "snoopy.php"; 
$snoopy = new Snoopy; 
$snoopy->cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //Camouflage sessionid
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; //Camouflage browser
$snoopy->referer = //www.jb51.net; // Disguise the source page address  http_referer 
$snoopy->rawheaders["Pragma"] = "no-cache"; //The HTTP header for the cache
$snoopy->rawheaders["X_FORWARDED_FOR"] = "127.0.0.101"; //Camouflage IP
$snoopy->submit($action,$formvars); 
echo $snoopy->results; 
?> 

It turns out that we can disguise session, disguise browser, disguise IP, and haha to do a lot of things.
For example, with verification code, authentication IP voting, you can keep casting.
Ps: here camouflage IP, actually is camouflage HTTP header, so the general IP obtained through REMOTE_ADDR is not camouflage,
Instead, those who get the IP through the HTTP header (the kind that prevents proxies) can make the IP themselves.
About how to verify the code, briefly say:
First, use a normal browser to view the page and find the corresponding sessionid of the verification code.
Write down both the sessionid and the captcha value,
Next, I'll use snoopy to forge it.
Principle: because it is the same sessionid, the verification code is the same as the first input.
4 sometimes we may need to forge more things, and snoopy has it all figured out for us
 
<?php 
$snoopy->proxy_host = "//www.jb51.net"; 
$snoopy->proxy_port = "8080"; //Using the agent
$snoopy->maxredirs = 2; //Number of redirection
$snoopy->expandlinks = true; //Whether the completion link is often used in the collection
//  For example, link to  /images/taoav.gif  Can be changed to its full link  <a href="//www.jb51.net/images/taoav.gif">//www.jb51.net/images/taoav.gif</a> 
$snoopy->maxframes = 5 //Maximum number of frames allowed
//Note that when you grab the frame, $snoopy-> Results returns an array
$snoopy->error //Returns an error message
?> 

Related articles: