


Detailed introduction to PHP collection class snoopy (snoopy usage tutorial)_PHP tutorial
Snoopy is a php class that is used to simulate the functions of a browser. It can obtain web content, send forms, and can be used to develop some collection programs and thief programs. This article introduces the usage tutorial of snoopy in detail.
Some features of Snoopy:
Fetch the content of the web page fetch
Fetch the text content of the web page (remove HTML tags) fetchtext
Fetch web links, form fetchlinks fetchform
Support proxy host
Supports basic username/password authentication
Support setting user_agent, referer (source), cookies and header content (header file)
Supports browser redirection and can control redirection depth
Can expand links in web pages into high-quality URLs (default)
Submit data and get return value
Support tracking HTML framework
Support passing cookies when redirecting
It only requires PHP 4 or above. Since it is a PHP class, there is no need to expand the support. The best choice when the server does not support curl,
Snoopy class methods and examples:
fetch($URI)
This is the method used to crawl the content of web pages.
The $URI parameter is the URL address of the crawled web page.
The fetched results are stored in $this->results.
If you are scraping a frame, Snoopy will track each frame and store it in an array, then store it in $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 web page.
fetchform($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 form content (form) in the web page.
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 web page.
By default, relative links will be automatically completed and converted into full URLs.
submit($URI,$formvars)
This method sends a confirmation form to the link address 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 of the web page 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 the link in the web page.
By default, relative links will be automatically completed and converted into full URLs.
Snoopy collection class attributes: (default value is in brackets)
$host Connected host
$port Connected port
$proxy_host The proxy host to use, if any
$proxy_port The proxy host port to use, if any
$agent User Agent Disguise (Snoopy v0.1)
$referer Origin information, if available
$cookies cookies if any
$rawheaders Other header information, if any
$maxredirs Maximum number of redirects, 0=not allowed (5)
$offsiteok whether or not to allow redirects off-site. (true)
$expandlinks Whether to complete all links to complete addresses (true)
$user Authentication username, if available
$pass Authentication username, if available
$accept http accept type (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*)
$error Where to report the error, if any
$response_code The response code returned from the server
$headers Headers returned from the server
$maxlength Maximum return data length
$read_timeout Read operation timeout (requires PHP 4 Beta 4+) Set to 0 for no timeout
$timed_out If a read operation times out, this attribute returns true (requires PHP 4 Beta 4+)
$maxframes Maximum number of frames allowed to be tracked
$status Status of the captured http
$temp_dir Temporary file directory (/tmp) that the web server can write to
$curl_path The directory of cURL binary, if there is no cURL binary, set it to false
Here is an example:
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"] = 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.jb51.net"))
{
echo "
".htmlspecialchars($snoopy->results)."n";
}
else
echo "error fetching document: ".$snoopy->error."n";
获取指定url内容
include("snoopy.php");
$snoopy = new Snoopy;
$snoopy->fetch($url); //获取所有内容
echo $snoopy->results; //显示结果
//可选以下
$snoopy->fetchtext //获取文本内容(去掉html代码)
$snoopy->fetchlinks //获取链接
$snoopy->fetchform //获取表单
?>
表单提交
$formvars["pwd"] = "admin";
$action = "http://www.jb51.net";//表单提交地址
$snoopy->submit($action,$formvars);//$formvars为提交的数组
echo $snoopy->results; //获取表单提交后的 返回的结果
//可选以下
$snoopy->submittext; //提交后只返回 去除html的 文本
$snoopy->submitlinks;//提交后只返回 链接
?>
既然已经提交的表单 那就可以做很多事情 接下来我们来伪装ip,伪装浏览器
伪装浏览器
$formvars["pwd"] = "lanfengye";
$action = "http://www.jb51.net";
include "snoopy.php";
$snoopy = new Snoopy;
$snoopy->cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //伪装sessionid
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; //伪装浏览器
$snoopy->referer = "http://www.jb51.net"; //伪装来源页地址 http_referer
$snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息
$snoopy->rawheaders["X_FORWARDED_FOR"] = "127.0.0.101"; //伪装ip
$snoopy->submit($action,$formvars);
echo $snoopy->results;
?>
It turns out that we can camouflage session, camouflage browser, camouflage IP, haha we can do a lot of things.
For example, if you bring a verification code and verify your IP to vote, you can vote non-stop.
ps: Disguising the IP here is actually disguising the http header, so the IP obtained through REMOTE_ADDR cannot be disguised,
On the contrary, those who obtain IP through http header (the kind that can prevent proxy) can create their own IP.
Regarding how to verify the code, let’s briefly talk:
First, use an ordinary browser to view the page and find the sessionid corresponding to the verification code,
Also note down the sessionid and verification code values,
Next, use snoopy to fake it.
Principle: Since it is the same sessionid, the verification code obtained is the same as the one entered for the first time.
Sometimes we may need to fake more things, snoopy completely thought of it for us
$snoopy->proxy_host = "http://www.jb51.net";
$snoopy->proxy_port = "8080"; //Use proxy
$snoopy->maxredirs = 2; //Number of redirects
$snoopy->expandlinks = true; //Whether to complete the link is often used during collection
// For example, the link is /images/taoav.gif, which can be changed to its full linkhttp://www.jb51. net/images/taoav.gif
$snoopy->maxframes = 5 //Maximum number of frames allowed
//Note that when grabbing the frame, $snoopy->results returns an array
$snoopy->error //Return error message
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools