


PHP collection class Snoopy.class.php introduction and download_PHP tutorial
Introduction and download of PHP collection class Snoopy.class.php
Snoopy is a very powerful PHP class that can be used to simulate a browser to obtain web content and send forms task. The following is a detailed introduction to the features and some common uses of Snoopy.class.php.
Official website: http://snoopy.sourceforge.net/ (If you cannot open foreign websites, you can use Tianxing Browser)
Download address: http://sourceforge.net/projects/snoopy/
Download address of this site: PHP collection library Snoopy.class.php download
Here are some features of Snoopy:
1. Fetch the content of the web page fetch
2. Fetch the text content of the web page (remove HTML tags) fetchtext
3. Fetch web page links, form fetchlinks fetchform
4. Support proxy host
5. Support basic username/password verification
6. Support setting user_agent, referer (source), cookies and header content (header file)
7. Supports browser redirection and can control redirection depth
8. Can expand links in web pages into high-quality URLs (default)
9. Submit data and get the return value
10. Support tracking HTML framework (added in v0.92)
11. Support passing cookies when redirecting
Note: Using Snoopy.class.php requires PHP 4 or above. Since it is a PHP class, there is no need to expand support. It is the best choice when the server does not support curl.
The following is an introduction to some commonly used class methods:
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, and the crawled 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.
Class attributes: (Default values are in brackets)
$host the connected host
$port The port to connect to
$proxy_host The proxy host to use, if any
$proxy_port The proxy host port to use, if any
$agent User agent masquerading (Snoopy v0.1)
$referer source 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 types (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*)
$error Where is the error reported, if any
$response_code Response code returned from the server
$headers Headers returned from the server
$maxlength The longest returned 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 The status of the captured http
$temp_dir The temporary file directory that the web server can write to (/tmp)
$curl_path cURL binary directory, if there is no cURL binary, set it to false
The following are some common usage examples:
(1) Capture the text on the home page of the PHP programmer’s notes website
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchtext("http://www.phpernote.com"); echo $snoopy->results;
(2) Grab all the links on the home page of the PHP programmer’s notes website
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchlinks("http://www.phpernote.com"); print_r($snoopy->results);
(3) Get what fields need to be sent to log in to Renren and what is the target address
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchform("http://www.renren.com/PLogin.do"); print_r($snoopy->results);
(4) Simulate login to Renren
<?php set_time_limit(0); require "Snoopy.class.php"; $snoopy=new Snoopy(); $snoopy->referer='http://www.renren.com/'; $snoopy->agent="Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0"; $submit_vars['email'] ='登陆账号'; $submit_vars['password'] ='登陆密码'; $url='http://www.renren.com/PLogin.do';//登陆数据提交的URL地址 $snoopy->submit($url,$submit_vars); $snoopy->fetch("http://www.renren.com/");//希望获取的页面数据 echo $snoopy->results;//www.phpernote.com
您可能感兴趣的文章
- php利用curl实现多线程的类,php curl多线程下载图片
- php snoopy采集类介绍
- PHP 利用 Curl Functions 实现多线程抓取网页和下载文件
- php实现将文件批量压缩打包下载
- 强大的PHP 图片处理类(水印、透明度、缩放、锐化、旋转、翻转、剪切、反色)
- 用PHP函数memory_get_usage获取当前PHP内存消耗量以实现程序的性能优化
- php限制文件下载速度的功能
- 如何去除codeIgniter开发的网站url里面的index.php字符串

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
