Home > Backend Development > PHP Tutorial > PHP collection class Snoopy.class.php introduction and download_PHP tutorial

PHP collection class Snoopy.class.php introduction and download_PHP tutorial

WBOY
Release: 2016-07-13 10:11:15
Original
1141 people have browsed it

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;
Copy after login

(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);
Copy after login

(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);
Copy after login

(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
Copy after login

您可能感兴趣的文章

  • 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类,可以利用该类模拟浏览器来完成获取网页内容和发送表单的任务。下面是...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template