PHP采集类Snoopy.class.php介绍以及下载
PHP采集类Snoopy.class.php介绍以及下载
Snoopy 是一个非常强大的PHP类,可以利用该类模拟浏览器来完成获取网页内容和发送表单的任务。下面是详细介绍Snoopy.class.php 的特点和一些常见的用法。
官方网站:http://snoopy.sourceforge.net/ (不能打开国外网站的可使用天行浏览器)
下载地址:http://sourceforge.net/projects/snoopy/
本站下载地址:PHP采集库Snoopy.class.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框架 (v0.92增加)
11、支持重定向的时候传递cookies
备注:使用 Snoopy.class.php 要求php4以上就可以了,由于本身是php一个类,无需扩支持,服务器不支持curl时候的最好选择。
下面是一些常用的类方法介绍:
fetch($URI)
这是为了抓取网页的内容而使用的方法。$URI参数是被抓取网页的URL地址,抓取的结果被存储在 $this->results 中。如果你正在抓取的是一个框架,Snoopy将会将每个框架追踪后存入数组中,然后存入 $this->results。
fetchtext($URI)
本方法类似于fetch(),唯一不同的就是本方法会去除HTML标签和其他的无关数据,只返回网页中的文字内容。
fetchform($URI)
本方法类似于fetch(),唯一不同的就是本方法会去除HTML标签和其他的无关数据,只返回网页中表单内容(form)。
fetchlinks($URI)
本方法类似于fetch(),唯一不同的就是本方法会去除HTML标签和其他的无关数据,只返回网页中链接(link)。默认情况下,相对链接将自动补全,转换成完整的URL。
submit($URI,$formvars)
本方法向$URL指定的链接地址发送确认表单。$formvars是一个存储表单参数的数组。
submittext($URI,$formvars)
本方法类似于submit(),唯一不同的就是本方法会去除HTML标签和其他的无关数据,只返回登陆后网页中的文字内容。
submitlinks($URI)
本方法类似于submit(),唯一不同的就是本方法会去除HTML标签和其他的无关数据,只返回网页中链接(link)。默认情况下,相对链接将自动补全,转换成完整的URL。
类属性: (缺省值在括号里)
$host 连接的主机
$port 连接的端口
$proxy_host 使用的代理主机,如果有的话
$proxy_port 使用的代理主机端口,如果有的话
$agent 用户代理伪装 (Snoopy v0.1)
$referer 来路信息,如果有的话
$cookies cookies, 如果有的话
$rawheaders 其他的头信息, 如果有的话
$maxredirs 最大重定向次数, 0=不允许 (5)
$offsiteok whether or not to allow redirects off-site. (true)
$expandlinks 是否将链接都补全为完整地址 (true)
$user 认证用户名, 如果有的话
$pass 认证用户名, 如果有的话
$accept http 接受类型 (image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*)
$error 哪里报错, 如果有的话
$response_code 从服务器返回的响应代码
$headers 从服务器返回的头信息
$maxlength 最长返回数据长度
$read_timeout 读取操作超时 (requires PHP 4 Beta 4+) 设置为0为没有超时
$timed_out 如果一次读取操作超时了,本属性返回 true (requires PHP 4 Beta 4+)
$maxframes 允许追踪的框架最大数量
$status 抓取的http的状态
$temp_dir 网页服务器能够写入的临时文件目录 (/tmp)
$curl_path cURL binary 的目录, 如果没有cURL binary就设置为 false
如下是几个常见的使用示例:
(1)抓取php程序员的笔记网站上首页页面上的文字
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchtext("http://www.phpernote.com"); echo $snoopy->results;
(2)抓取php程序员的笔记网站首页的页面的所有链接
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchlinks("http://www.phpernote.com"); print_r($snoopy->results);
(3)获取登陆人人网需要发送什么字段,目标地址是什么
<?php include 'Snoopy.class.php'; $snoopy=new Snoopy; $snoopy->fetchform("http://www.renren.com/PLogin.do"); print_r($snoopy->results);
(4)模拟登陆人人网
<?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 and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

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 and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
