php中Snoopy类用法实例

yipeiwu_com6年前PHP代码库

本文实例讲述了php中Snoopy类用法。分享给大家供大家参考。具体分析如下:

这里演示了php中如何通过Snoopy抓取网页信息

snoopy类的下载地址:http://sourceforge.net/projects/snoopy/

/*
You need the snoopy.class.php from 
http://snoopy.sourceforge.net/
*/
include("snoopy.class.php");
$snoopy = new Snoopy;
// need an proxy?:
//$snoopy->proxy_host = "my.proxy.host";
//$snoopy->proxy_port = "8080";
// set browser and referer:
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$snoopy->referer = "http://www.jonasjohn.de/";
// set some cookies:
$snoopy->cookies["SessionID"] = '238472834723489';
$snoopy->cookies["favoriteColor"] = "blue";
// set an raw-header:
$snoopy->rawheaders["Pragma"] = "no-cache";
// set some internal variables:
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
// set username and password (optional)
//$snoopy->user = "joe";
//$snoopy->pass = "bloe";
// fetch the text of the website www.google.com:
if($snoopy->fetchtext("http://www.google.com")){ 
  // other methods: fetch, fetchform, fetchlinks, submittext and submitlinks
  // response code:
  print "response code: ".$snoopy->response_code."<br/>\n";
  // print the headers:
  print "<b>Headers:</b><br/>";
  while(list($key,$val) = each($snoopy->headers)){
    print $key.": ".$val."<br/>\n";
  }
  print "<br/>\n";
 
  // print the texts of the website:
  print "<pre>".htmlspecialchars($snoopy->results)."</pre>\n";
}
else {
  print "Snoopy: error while fetching document: ".$snoopy->error."\n";
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP图片库imagemagick安装方法

本文较为详细的讲述了PHP图片库imagemagick的安装方法。分享给大家供大家参考。具体方法如下: 1.下载ImageMagick http://www.imagemagick.or...

php正则取img标记中任意属性(正则替换去掉或改变图片img标记中的任意属性)

因有一项目新闻发布系统,数据库内容字段中存储的是原图的路径(当然还有其他文字内容啦,内容里插图时,存的是图片路径),但前台想使用缩略图,琢磨1小时余,得到以下结果,可解决问题(取img标...

用php代码限制国内IP访问我们网站

利用淘宝的IP接口来判断IP,是否是国内的ip,是国内(CN)的就不允许访问。 $ip = $_SERVER['REMOTE_ADDR']; $content = file_get...

header与缓冲区之间的深层次分析

测试header之前有输出 <?php echo 'hello world!'; header('content-type: text/html;charset=ut...

php gd等比例缩放压缩图片函数

本文实例为大家分享了php gd等比例缩放压缩图片函数,供大家参考,具体内容如下 <?php /** * desription 判断是否gif动画 *...