Snoopy-powerful PHP collection class usage details and examples: collection, simulated login and camouflage browser

Source: Internet
Author: User
Snoopy is a php class used to simulate browser functions. it can obtain webpage content and send forms. To run Snoopy correctly, the PHP version of your server is later than 4 and PCRE (PerlCompatibleRegularExpressions) is supported. basic LAMP services are supported. : & Nbsp; http: // sourceforge.

Snoopy is a php class used to simulate browser functions. it can obtain webpage content and send forms. To run Snoopy correctly, the PHP version of your server is later than 4 and PCRE (Perl Compatible Regular Expressions) is supported. basic LAMP services are supported.

:? Http://sourceforge.net/project/showfiles.php? Group_id = 2091

I. Some features of Snoopy:

1. fetch the webpage content

2. capture the text content of the webpage (remove HTML tags) fetchtext

3. capture the link of the webpage, form fetchlinks fetchform

4. support for proxy hosts

5. support for basic user name/password verification

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. cookies can be transferred when redirection is supported. you only need php4 or above. because it is a php class, you do not need to expand the support. The server is the best choice when curl is not supported.

II. Category methods:

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.

III. class attributes: (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 to request an offline website, not http header (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 message, if any

$ Response_code response code returned from the server

$ Headers header information returned from the server

$ Maxlength: maximum length of data returned at a time (500000)

$ Read_timeout: the read operation times out. if it is set to 0, the read operation does not time out.

$ 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 sample code:

1. get the content of a specified url

$ Url = "http://www.icultivator.com"; include ("snoopy. php "); $ snoopy = new Snoopy; $ snoopy-> fetch ($ url); // Obtain all content echo $ snoopy-> results; // display the result // optional $ snoopy-> fetchtext // get the text content (remove the html code) $ snoopy-> fetchlinks // Obtain the link $ snoopy-> fetchform // Obtain the form

2. form submission

$ Formvars ["username"] = "admin"; $ formvars ["pwd"] = "admin"; $ action = "http://www.4wei.cn "; // 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 values: $ snoopy-> submittext; // after the form is submitted, 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

$ Formvars ["username"] = "admin"; $ formvars ["pwd"] = "admin"; $ action = "http://www.icultivator.com"; 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.icultivator.com; // disguise the source page address http_referer $ snoopy-> rawheaders ["Pragma"] = "no-cache "; // cache http header information $ snoopy-> rawheaders ["X_FORWARDED_FOR"] = "127.0.0.101"; // disguise ip $ 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.

$ Snoopy-> proxy_host = "http://www.icultivator.com"; $ snoopy-> proxy_port = "8080"; // use proxy $ snoopy-> maxredirs = 2; // redirect times $ snoopy-> expandlinks = true; // whether to enable the full link is frequently used during Collection. // for example, if the link is/images/taoav.gif, you can change it to its full link metadata-> maxframes = 5 // maximum number of frames allowed/ /when capturing the framework, $ snoopy-> results returns an array $ snoopy-> error // returns an error message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.