- /**
- * @name Snoopy手册中文版
- * @author 毛毛虫 wangchong1985@gmail.com
- * @version Snoopy - the PHP net client v1.2.2
- * @link http://www.wangchong.org
- * @since 2008-04-27
- */
名称:
Snoopy - the PHP net client v1.2.2
概要:
- 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;
描述:
Snoopy是什么?
Snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。
Snoopy的一些特点:
* 方便抓取网页的内容
* 方便抓取网页的文本内容 (去除HTML标签)
* 方便抓取网页的链接
* 支持代理主机
* 支持基本的用户名/密码验证
* 支持设置 user_agent, referer(来路), cookies 和 header content(头文件)
* 支持浏览器转向,并能控制转向深度
* 能把网页中的链接扩展成高质量的url(默认)
* 方便提交数据并且获取返回值
* 支持跟踪HTML框架(v0.92增加)
* 支持再转向的时候传递cookies (v0.92增加)
Read the rest of this entry »
snoopy这个采集类库是个很好玩的东西,简单而且使用,一般的采集应付起来绰绰有余。
最近一个哥们要看盗墓笔记的全本TXT文档,让我帮他采集,想了下决定用snoopy和一个好玩的类库htmlsql来做,htmlsql第一次使用,感觉比较好玩,写SQL的感觉非常有趣,就是灵活性上不是很突出,但做这种小的采集足够了,可能是因为第一次使用这个类库,并不是很顺利,写了两个多钟头,才搞定这个采集,这里放出源码供大家下载吧,想玩玩的可以拿去参考下。
展示部分代码:
- <?php
- include_once("./snoopy.class.php");
- include_once("./htmlsql.class.php");
- require_once("./function.php");
- //防止页面超时
- set_time_limit(0);
- //生成文本文档名称
- $name="怒海潜沙";//自定义文件名(注意自己修改)
- $txt_name=$name.".txt";
- $zhangjie="nu-hai-qian-sha";//这个程序写的并不是很智能,每个章节的链接地址还要自己修改下(注意自己修改)
- $max="46";//最大采集章节数(注意自己修改)
- $wsql = new htmlsql();
- for($i=1;$i<=$max;$i++){
- $a=sprintf("%02d", $i);
- $url="http://www.daomubiji.com/$zhangjie-$a.html";
- // connect to a URL
- if (!$wsql->connect('url', $url)){
- print 'Error while connecting: ' . $wsql->error;
- exit;
- }
- if(!$wsql->query('SELECT * FROM h1')){
- print "Query error: " . $wsql->error;
- exit;
- }
- // show results:
- foreach($wsql->fetch_array() as $row){
- writeStatistic("\r\n".$row['text']."\r\n",$txt_name);
- $echo=iconv("UTF-8", "GBK", $row['text']);
- //print_r($row);
- }
- $wsql->isolate_content('<script src=http://busjs.vodone.cn/bus/ownerjs/advjs_47/47093/47093_56564_p7_.js></script>','<p align="center">');
- if (!$wsql->query('SELECT * FROM *')){
- print "Query error: " . $wsql->error;
- exit;
- }
- // show results:
- foreach($wsql->fetch_array() as $row){
- writeStatistic(strip_tags($row['text'])."\r\n",$txt_name);
- //print_r($row);
- }
- print "$i. 章节: $echo 采集完成.....<br>";
- print "--------------------------------------------------------<br>";
- flush();
- }
- print "卷:$name 全部采集完成......";
- ?>
程序包下载:
snoopy与htmlsql实例程序包
官方的简介:
snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。
下面是它的一些特征:
1、方便抓取网页的内容
2、方便抓取网页的文字(去掉HTML代码)
3、方便抓取网页的链接
4、支持代理主机
5、支持基本的用户/密码认证模式
6、支持自定义用户agent,referer,cookies和header内容
7、支持浏览器转向,并能控制转向深度
8、能把网页中的链接扩展成高质量的url(默认)
9、方便提交数据并且获取返回值
10、支持跟踪HTML框架(v0.92增加)
11、支持再转向的时候传递cookies
Read the rest of this entry »
