Snoopy - the PHP net client v1.2.4

Snoopy是一个php类,用来模拟浏览器的功能,可以获取网页内容,发送表单。
Snoopy的特点:
1、抓取网页的内容 fetch
2、抓取网页的文本内容 (去除HTML标签) fetchtext
3、抓取网页的链接,表单 fetchlinks fetchform
4、支持代理主机
5、支持基本的用户名/密码验证
6、支持设置 user_agent, referer(来路), cookies 和 header content(头文件)
7、支持浏览器重定向,并能控制重定向深度
8、能把网页中的链接扩展成高质量的url(默认)
9、提交数据并且获取返回值
10、支持跟踪HTML框架
11、支持重定向的时候传递cookies
要求php4以上就可以了,由于本身是php一个类,无需扩支持,服务器不支持curl时候的最好选择。

概要方法:

    include "Snoopy.class.php";
$snoopy = new Snoopy; $snoopy->fetchtext("http://www.php.net/");
print $snoopy->results; $snoopy->fetchlinks("http://www.phpbuilder.com/");
print $snoopy->results; $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html"; $submit_vars["q"] = "amiga";
$submit_vars["submit"] = "Search!";
$submit_vars["searchhost"] = "Altavista"; $snoopy->submit($submit_url,$submit_vars);
print $snoopy->results; $snoopy->maxframes=5;
$snoopy->fetch("http://www.ispi.net/");
echo "<PRE>\n";
echo htmlentities($snoopy->results[0]);
echo htmlentities($snoopy->results[1]);
echo htmlentities($snoopy->results[2]);
echo "</PRE>\n"; $snoopy->fetchform("http://www.altavista.com");
print $snoopy->results; 

类方法说明:

    fetch($URI)
----------- This is the method used for fetching the contents of a web page.
$URI is the fully qualified URL of the page to fetch.
The results of the fetch are stored in $this->results.
If you are fetching frames, then $this->results
contains each frame fetched in an array. fetchtext($URI)
--------------- This behaves exactly like fetch() except that it only returns
the text from the page, stripping out html tags and other
irrelevant data. fetchform($URI)
--------------- This behaves exactly like fetch() except that it only returns
the form elements from the page, stripping out html tags and other
irrelevant data. fetchlinks($URI)
---------------- This behaves exactly like fetch() except that it only returns
the links from the page. By default, relative links are
converted to their fully qualified URL form. submit($URI,$formvars)
---------------------- This submits a form to the specified $URI. $formvars is an
array of the form variables to pass. submittext($URI,$formvars)
-------------------------- This behaves exactly like submit() except that it only returns
the text from the page, stripping out html tags and other
irrelevant data. submitlinks($URI)
---------------- This behaves exactly like submit() except that it only returns
the links from the page. By default, relative links are
converted to their fully qualified URL form.

类 VARIABLES: (default value in parenthesis)

    $host            the host to connect to
$port the port to connect to
$proxy_host the proxy host to use, if any
$proxy_port the proxy port to use, if any
$agent the user agent to masqerade as (Snoopy v0.1)
$referer referer information to pass, if any
$cookies cookies to pass if any
$rawheaders other header info to pass, if any
$maxredirs maximum redirects to allow. 0=none allowed. (5)
$offsiteok whether or not to allow redirects off-site. (true)
$expandlinks whether or not to expand links to fully qualified URLs (true)
$user authentication username, if any
$pass authentication password, if any
$accept http accept types (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, )
$error where errors are sent, if any
$response_code responde code returned from server
$headers headers returned from server
$maxlength max return data length
$read_timeout timeout on read operations (requires PHP 4 Beta 4+)
set to 0 to disallow timeouts
$timed_out true if a read operation timed out (requires PHP 4 Beta 4+)
$maxframes number of frames we will follow
$status http status of fetch
$temp_dir temp directory that the webserver can write to. (/tmp)
$curl_path system path to cURL binary, set to false if none

EXample:

    Example:     fetch a web page and display the return headers and
the contents of the page (html-escaped): include "Snoopy.class.php";
$snoopy = new Snoopy; $snoopy->user = "joe";
$snoopy->pass = "bloe"; if($snoopy->fetch("http://www.slashdot.org/"))
{
echo "response code: ".$snoopy->response_code."<br>\n";
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n"; echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n"; Example: submit a form and print out the result headers
and html-escaped page: include "Snoopy.class.php";
$snoopy = new Snoopy; $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html"; $submit_vars["q"] = "amiga";
$submit_vars["submit"] = "Search!";
$submit_vars["searchhost"] = "Altavista"; if($snoopy->submit($submit_url,$submit_vars))
{
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n"; echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n"; Example: showing functionality of all the variables: include "Snoopy.class.php";
$snoopy = new Snoopy; $snoopy->proxy_host = "my.proxy.host";
$snoopy->proxy_port = "8080"; $snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)";
$snoopy->referer = "http://www.microsnot.com/"; $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.phpbuilder.com"))
{
while(list($key,$val) = each($snoopy->headers))
echo $key.": ".$val."<br>\n";
echo "<p>\n"; echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n"; Example: fetched framed content and display the results include "Snoopy.class.php";
$snoopy = new Snoopy; $snoopy->maxframes = 5; if($snoopy->fetch("http://www.ispi.net/"))
{
echo "<PRE>".htmlspecialchars($snoopy->results[0])."</PRE>\n";
echo "<PRE>".htmlspecialchars($snoopy->results[1])."</PRE>\n";
echo "<PRE>".htmlspecialchars($snoopy->results[2])."</PRE>\n";
}
else
echo "error fetching document: ".$snoopy->error."\n";

Snoopy.class.php使用手册的更多相关文章

  1. Snoopy.class.php介绍

    Snoopy是一个开源的模拟抓取工具,找到一个不错的介绍网页 记录一下: php开源采集类Snoopy.class.php功能使用介绍与下载地址 Snoopy.class.php使用手册 还有一个介绍 ...

  2. simple_html_dom配合snoopy使用

    https://github.com/samacs/simple_html_dom Snoopy的特点是“大”和“全”,一个fetch什么都采到了,可以作为采集的第一步.接下来就需要用simple_h ...

  3. FREERTOS 手册阅读笔记

    郑重声明,版权所有! 转载需说明. FREERTOS堆栈大小的单位是word,不是byte. 根据处理器架构优化系统的任务优先级不能超过32,If the architecture optimized ...

  4. JS魔法堂:不完全国际化&本地化手册 之 理論篇

    前言  最近加入到新项目组负责前端技术预研和选型,其中涉及到一个熟悉又陌生的需求--国际化&本地化.熟悉的是之前的项目也玩过,陌生的是之前的实现仅仅停留在"有"的阶段而已. ...

  5. 转职成为TypeScript程序员的参考手册

    写在前面 作者并没有任何可以作为背书的履历来证明自己写作这份手册的分量. 其内容大都来自于TypeScript官方资料或者搜索引擎获得,期间掺杂少量作者的私见,并会标明. 大部分内容来自于http:/ ...

  6. Redis学习手册(目录)

    为什么自己当初要选择Redis作为数据存储解决方案中的一员呢?现在能想到的原因主要有三.其一,Redis不仅性能高效,而且完全免费.其二,是基于C/C++开发的服务器,这里应该有一定的感情因素吧.最后 ...

  7. JS魔法堂:不完全国际化&本地化手册 之 实战篇

    前言  最近加入到新项目组负责前端技术预研和选型,其中涉及到一个熟悉又陌生的需求--国际化&本地化.熟悉的是之前的项目也玩过,陌生的是之前的实现仅仅停留在"有"的阶段而已. ...

  8. Windows API 函数列表 附帮助手册

    所有Windows API函数列表,为了方便查询,也为了大家查找,所以整理一下贡献出来了. 帮助手册:700多个Windows API的函数手册 免费下载 API之网络函数 API之消息函数 API之 ...

  9. linux命令在线手册

    下面几个网址有一些 Linux命令的在线手册,而且还是中文的,还可以搜索.非常方便 Linux命令手册 Linux命令大全 Linux中文man在线手册 每日一linux命令

随机推荐

  1. 记一次antlr错误:ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.2ANTLR

    场景:重构spark 2.1版本的sql语法.因此 需要使用antlr: 前期准备:idea安装了antlr插件(antlr的4.7.2版本) 因此在maven工程中添加了antlr的依赖: < ...

  2. checkbox为空

    <view:qrytr> <view:qrytd width="15%" heightshow="true">请选择执法范围:</ ...

  3. shell 里的正则

    #!/bin/bash variable="This is a fine mess." echo "$variable" # Regex matching wi ...

  4. Linux设备驱动程序 之 原子操作

    原子整数操作 当共享资源是一个简单的整数值时,可以使用内核提供的一种原子的整数类型,称为atomic_t,定义在<linux/types.h>中,操作定义在<linux/atomic ...

  5. 火车购票问题(16年ccf)

    火车购票问题(16年ccf) 问题描述 请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一节车厢有20排.每一排5个座位.为方便起见,我们用1到100来给所有的座位编号,第一 ...

  6. 数据库 | Oracle数据库查表空间使用情况

    平时在使用Oracle的时候,如果业务中的数据量激增.数据量变大,很有可能就会有表空间不足的情况,需要重点关注.今天我们分享下如何查看表空间的使用情况. 一.如何查看使用状况 我们废话不说,先直接贴上 ...

  7. Win10+VS2017配置pthread

    0.pthread源码下载:https://sourceware.org/pthreads-win32/ 1.下载pthreads-w32-2-9-1-release.zip完毕后,解压,内容如下 其 ...

  8. 在业务控制方法中收集List<JavaBean>参数

    @Controller @RequestMapping(value="/user") public class UserAction { @RequestMapping(value ...

  9. 007-IP报文协议

    一.概述 IP协议是将多个包交换网络连接起来,它在源地址和目的地址之间传送一种称之为数据包的东西,它还提供对数据大小的重新组装功能,以适应不同网络对包大小的要求. IP不提供可靠的传输服务,它不提供端 ...

  10. [GPU] Install H2O.ai

    一.前言 主页:https://www.h2o.ai/products/h2o4gpu/ GPU版本安装:h2oai/h2o4gpu 采用GPU,能否成为超越下面链接中实验的存在? [ML] LIBS ...