Snoopy中文手册(毛毛虫翻译)

Filed under: Spider | 9 Comments »
Posted on
  1. /**
  2. * @name Snoopy手册中文版
  3. * @author 毛毛虫 wangchong1985@gmail.com
  4. * @version Snoopy - the PHP net client v1.2.2
  5. * @link http://www.wangchong.org
  6. * @since 2008-04-27
  7. */

名称:

Snoopy - the PHP net client v1.2.2

概要:

  1. include "Snoopy.class.php";
  2.     $snoopy = new Snoopy;
  3.    
  4.     $snoopy->fetchtext("http://www.php.net/");
  5.     print $snoopy->results;
  6.    
  7.     $snoopy->fetchlinks("http://www.phpbuilder.com/");
  8.     print $snoopy->results;
  9.    
  10.     $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
  11.    
  12.     $submit_vars["q"] = "amiga";
  13.     $submit_vars["submit"] = "Search!";
  14.     $submit_vars["searchhost"] = "Altavista";
  15.        
  16.     $snoopy->submit($submit_url,$submit_vars);
  17.     print $snoopy->results;
  18.    
  19.     $snoopy->maxframes=5;
  20.     $snoopy->fetch("http://www.ispi.net/");
  21.     echo "<PRE>\n";
  22.     echo htmlentities($snoopy->results[0]);
  23.     echo htmlentities($snoopy->results[1]);
  24.     echo htmlentities($snoopy->results[2]);
  25.     echo "</PRE>\n";
  26.  
  27.     $snoopy->fetchform("http://www.altavista.com");
  28.     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与htmlsql实例(盗墓笔记采集)

Filed under: Spider | 3 Comments »
Posted on

snoopy这个采集类库是个很好玩的东西,简单而且使用,一般的采集应付起来绰绰有余。
最近一个哥们要看盗墓笔记的全本TXT文档,让我帮他采集,想了下决定用snoopy和一个好玩的类库htmlsql来做,htmlsql第一次使用,感觉比较好玩,写SQL的感觉非常有趣,就是灵活性上不是很突出,但做这种小的采集足够了,可能是因为第一次使用这个类库,并不是很顺利,写了两个多钟头,才搞定这个采集,这里放出源码供大家下载吧,想玩玩的可以拿去参考下。
展示部分代码:

  1. <?php
  2. include_once("./snoopy.class.php");
  3. include_once("./htmlsql.class.php");
  4. require_once("./function.php");
  5. //防止页面超时
  6. set_time_limit(0);
  7. //生成文本文档名称
  8. $name="怒海潜沙";//自定义文件名(注意自己修改)
  9. $txt_name=$name.".txt";
  10. $zhangjie="nu-hai-qian-sha";//这个程序写的并不是很智能,每个章节的链接地址还要自己修改下(注意自己修改)
  11. $max="46";//最大采集章节数(注意自己修改)
  12. $wsql = new htmlsql();
  13. for($i=1;$i<=$max;$i++){
  14.     $a=sprintf("%02d", $i);
  15.     $url="http://www.daomubiji.com/$zhangjie-$a.html";
  16.     // connect to a URL
  17.     if (!$wsql->connect('url', $url)){
  18.         print 'Error while connecting: ' . $wsql->error;
  19.         exit;
  20.     }
  21.  
  22.     if(!$wsql->query('SELECT * FROM h1')){
  23.         print "Query error: " . $wsql->error;
  24.         exit;
  25.     }
  26.  
  27.     // show results:
  28.     foreach($wsql->fetch_array() as $row){
  29.         writeStatistic("\r\n".$row['text']."\r\n",$txt_name);
  30.         $echo=iconv("UTF-8", "GBK", $row['text']);
  31.         //print_r($row);   
  32.     } 
  33.  
  34.     $wsql->isolate_content('<script src=http://busjs.vodone.cn/bus/ownerjs/advjs_47/47093/47093_56564_p7_.js></script>','<p align="center">');
  35.  
  36.     if (!$wsql->query('SELECT * FROM *')){
  37.         print "Query error: " . $wsql->error;
  38.         exit;
  39.     }
  40.  
  41.     // show results:
  42.     foreach($wsql->fetch_array() as $row){
  43.         writeStatistic(strip_tags($row['text'])."\r\n",$txt_name);
  44.         //print_r($row);   
  45.     }
  46.     print "$i. 章节: $echo 采集完成.....<br>";
  47.     print "--------------------------------------------------------<br>";
  48.     flush();
  49. }
  50. print "卷:$name 全部采集完成......";
  51. ?>

程序包下载:
snoopy与htmlsql实例程序包

snoopy——PHP版的网络客户端

Filed under: Spider | 1 Comment »
Posted on

官方的简介:
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 »