Snoopy's powerful PHP collection class uses instance code. : Www.jb51.netcodes33397.html Snoopy some features: 1 capture the content of the web page fetch2 capture the web page text content (remove HTML tags) fetchtext3 capture web page chain: http://www.jb51.net/codes/33397.html
Some features of Snoopy:
1. fetch the webpage content
2. fetchtext
3. capture the link of the web page. The form is fetchlinks fetchform.
4. proxy host supported
5. basic user name/password verification is supported.
6. you can set user_agent, referer, cookies, and header content)
7. supports browser redirection and can control the depth of redirection.
8. extend the link in the webpage to a high-quality url (default)
9 submit data and obtain the returned value
10 support tracking HTML framework
11. sending cookies during redirection
The php4 and above are required. because it is a php class, it is the best choice when the server does not need to be expanded and curl is not supported,
Class method:
Fetch ($ URI)
----
This method is used to capture the content of a webpage.
$ URI is the URL of the webpage to be crawled.
The captured results are stored in $ this-> results.
If you are capturing a framework, Snoopy will track each frame and store it in an array, and then save it to $ this-> results.
Fetchtext ($ URI)
-----
This method is similar to fetch (). The only difference is that this method will remove HTML tags and other irrelevant data and only return the text content in the webpage.
Fetchform ($ URI)
-----
This method is similar to fetch (). The only difference is that this method will remove the HTML tag and other irrelevant data and only return the form content (form) in the webpage ).
Fetchlinks ($ URI)
------
This method is similar to fetch (). The only difference is that this method will remove HTML tags and other irrelevant data and only return links in the webpage ).
By default, the relative link is automatically completed and converted to a complete URL.
Submit ($ URI, $ formvars)
--------
This method sends a confirmation form to the URL specified by $ URL. $ Formvars is an array that stores form parameters.
Submittext ($ URI, $ formvars)
---------
This method is similar to submit (). The only difference is that this method will remove HTML tags and other irrelevant data and only return the text content on the webpage after login.
Submitlinks ($ URI)
------
This method is similar to submit (). The only difference is that this method will remove HTML tags and other irrelevant data and only return links in the webpage ).
By default, the relative link is automatically completed and converted to a complete URL.
Class property: (the default value is in brackets)
$ Host connected host
$ Port connection port
$ Proxy_host: the proxy host used, if any
$ Proxy_port indicates the proxy Host Port used. If yes
$ Agent User proxy disguise (Snoopy v0.1)
$ Referer information, if any
$ Cookies, if any
$ Rawheaders other header information, if any
$ Maxredirs maximum redirect times, 0 = not allowed (5)
$ Offsiteok whether or not to allow redirects off-site. (true)
$ Expandlinks: whether to add all links to the full address (true)
$ User authentication username, if any
$ Pass authentication username, if any
$ Accept http accept type (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg ,*/*)
$ Error: where is the error reported? if Yes
$ Response_code response code returned from the server
$ Headers header information returned from the server
$ Maxlength: maximum length of returned data
$ Read_timeout read operation timeout (requires PHP 4 Beta 4 +)
Set 0 to no timeout
$ Timed_out if a read operation times out, this attribute returns true (requires PHP 4 Beta 4 +)
$ Maxframes maximum number of frames that can be tracked
$ Status indicates the http status captured.
$ Temp_dir temporary file directory (/tmp) that can be written by the webpage server)
$ Curl_path cURL binary Directory. If no cURL binary is available, set it to false.
The following is a demo
The code is as follows:
Include "Snoopy. class. php ";
$ Snoopy = new Snoopy;
$ Snoopy-> proxy_host = "http://www.jb51.net ";
$ Snoopy-> proxy_port = "80 ";
$ Snoopy-> agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98 )";
$ Snoopy-> referer = "http://www.jb51.net ";
$ Snoopy-> cookies ["SessionID"] = 238472821323489l;
$ 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.jb51.net "))
{
Echo"
".htmlspecialchars($snoopy->results)."
\ N ";
}
Else
Echo "error fetching document:". $ snoopy-> error. "\ n ";
The following are some code snippets:
1. get the content of a specified url
The code is as follows:
$ Url = "http://www.jb51.net ";
Include ("snoopy. php ");
$ Snoopy = new Snoopy;
$ Snoopy-> fetch ($ url); // get all content
Echo $ snoopy-> results; // display the result
// Optional
$ Snoopy-> fetchtext // get text content (remove html code)
$ Snoopy-> fetchlinks // Obtain the link
$ Snoopy-> fetchform // Obtain the form
?>
2. form submission
The code is as follows:
$ Formvars ["username"] = "admin ";
$ Formvars ["pwd"] = "admin ";
$ Action = "http://www.jb51.net"; // form submission address
$ Snoopy-> submit ($ action, $ formvars); // $ formvars is the submitted array
Echo $ snoopy-> results; // obtain the result returned after the form is submitted.
// Optional
$ Snoopy-> submittext; // after submission, only the html-removed text is returned.
$ Snoopy-> submitlinks; // after submission, only the link is returned.
?>
Since the form has been submitted, we can do a lot of things. next we will disguise the ip address and the browser.
3 disguise
The code is as follows:
$ Formvars ["username"] = "admin ";
$ Formvars ["pwd"] = "admin ";
$ Action = "http://www.jb51.net ";
Include "snoopy. php ";
$ Snoopy = new Snoopy;
$ Snoopy-> cookies ["PHPSESSID"] = 'fc0000b1918bd522cc863f000090e6fff7 '; // disguise sessionid
$ Snoopy-> agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; // camouflage browser
$ Snoopy-> referer = http://www.jb51.net; // camouflage source page address http_referer
$ Snoopy-> rawheaders ["Pragma"] = "no-cache"; // The http header information of the cache
$ Snoopy-> rawheaders ["X_FORWARDED_FOR"] = "127.0.0.101"; // disguise ip address
$ Snoopy-> submit ($ action, $ formvars );
Echo $ snoopy-> results;
?>
In the past, we could disguise session as a web browser and ip address, and haha could do a lot of things.
For example, you can vote for an ip address with a verification code.
Ps: Here, the disguised ip address is actually an http header, so the ip address obtained through REMOTE_ADDR cannot be disguised,
Instead, ip addresses obtained through http headers (which can prevent proxies) can be created by themselves.
Let's briefly describe how to use the verification code:
First, use a normal browser to view the page and find the sessionid corresponding to the verification code,
Write down sessionid and verification code value at the same time,
Next, we will use snoopy to forge.
Principle: because it is the same sessionid, the verification code obtained is the same as the one entered for the first time.
4. sometimes we may need to forge more things. snoopy thought of it for us.
The code is as follows:
$ Snoopy-> proxy_host = "http://www.jb51.net ";
$ Snoopy-> proxy_port = "8080"; // use a proxy
$ Snoopy-> maxredirs = 2; // redirect times
$ Snoopy-> expandlinks = true; // whether to complete the link is often used during Collection
// For example, the link for/images/taoav.gif can be changed to its full link http://www.jb51.net/images/taoav.gif </a>
$ Snoopy-> maxframes = 5 // maximum number of frames allowed
// When capturing the frame, $ snoopy-> results returns an array.
$ Snoopy-> error // error message returned
?>
Refer http://www.jb51.net/codes/33397.html Snoopy some features: 1 capture the content of the web page fetch 2 capture the text content of the web page (remove HTML tags) fetchtext 3 capture the web page chain...