search
HomeBackend DevelopmentPHP TutorialPHP 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字符串

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/930520.htmlTechArticlePHP采集类Snoopy.class.php介绍以及下载 Snoopy 是一个非常强大的PHP类,可以利用该类模拟浏览器来完成获取网页内容和发送表单的任务。下面是...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?How can you protect against Cross-Site Scripting (XSS) attacks related to sessions?Apr 23, 2025 am 12:16 AM

To protect the application from session-related XSS attacks, the following measures are required: 1. Set the HttpOnly and Secure flags to protect the session cookies. 2. Export codes for all user inputs. 3. Implement content security policy (CSP) to limit script sources. Through these policies, session-related XSS attacks can be effectively protected and user data can be ensured.

How can you optimize PHP session performance?How can you optimize PHP session performance?Apr 23, 2025 am 12:13 AM

Methods to optimize PHP session performance include: 1. Delay session start, 2. Use database to store sessions, 3. Compress session data, 4. Manage session life cycle, and 5. Implement session sharing. These strategies can significantly improve the efficiency of applications in high concurrency environments.

What is the session.gc_maxlifetime configuration setting?What is the session.gc_maxlifetime configuration setting?Apr 23, 2025 am 12:10 AM

Thesession.gc_maxlifetimesettinginPHPdeterminesthelifespanofsessiondata,setinseconds.1)It'sconfiguredinphp.iniorviaini_set().2)Abalanceisneededtoavoidperformanceissuesandunexpectedlogouts.3)PHP'sgarbagecollectionisprobabilistic,influencedbygc_probabi

How do you configure the session name in PHP?How do you configure the session name in PHP?Apr 23, 2025 am 12:08 AM

In PHP, you can use the session_name() function to configure the session name. The specific steps are as follows: 1. Use the session_name() function to set the session name, such as session_name("my_session"). 2. After setting the session name, call session_start() to start the session. Configuring session names can avoid session data conflicts between multiple applications and enhance security, but pay attention to the uniqueness, security, length and setting timing of session names.

How often should you regenerate session IDs?How often should you regenerate session IDs?Apr 23, 2025 am 12:03 AM

The session ID should be regenerated regularly at login, before sensitive operations, and every 30 minutes. 1. Regenerate the session ID when logging in to prevent session fixed attacks. 2. Regenerate before sensitive operations to improve safety. 3. Regular regeneration reduces long-term utilization risks, but the user experience needs to be weighed.

How do you set the session cookie parameters in PHP?How do you set the session cookie parameters in PHP?Apr 22, 2025 pm 05:33 PM

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

What is the main purpose of using sessions in PHP?What is the main purpose of using sessions in PHP?Apr 22, 2025 pm 05:25 PM

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How can you share sessions across subdomains?How can you share sessions across subdomains?Apr 22, 2025 pm 05:21 PM

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function