首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

PHP采撷利器:Snoopy 试用心得

2012-11-07 
PHP采集利器:Snoopy 试用心得??//echo var_dump($_SERVER)include(Snoopy.class.php)$snoopy new S

PHP采集利器:Snoopy 试用心得

?

<? //echo var_dump($_SERVER); include("Snoopy.class.php"); $snoopy = new Snoopy; $snoopy->agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1";//这项是浏览器信息,前面你用什么浏览器查看cookie,就用那个浏览器的信息(ps:$_SERVER可以查看到浏览器的信息) $snoopy->referer = "http://bbs.phpchina.com/index.php"; $snoopy->expandlinks = true; $snoopy->rawheaders["COOKIE"]="__utmz=17229162.1227682761.29.7.utmccn=(referral)|utmcsr=phpchina.com|utmcct=/html/index.html|utmcmd=referral; cdbphpchina_smile=1D2D0D1; cdbphpchina_cookietime=2592000; __utma=233700831.1562900865.1227113506.1229613449.1231233266.16; __utmz=233700831.1231233266.16.8.utmccn=(referral)|utmcsr=localhost:8080|utmcct=/test3.php|utmcmd=referral; __utma=17229162.1877703507.1227113568.1231228465.1231233160.58; uchome_loginuser=sinopf; xscdb_cookietime=2592000; __utmc=17229162; __utmb=17229162; cdbphpchina_sid=EX5w1V; __utmc=233700831; cdbphpchina_visitedfid=17; cdbphpchinaO766uPYGK6OWZaYlvHSuzJIP22VpwEMGnPQAuWCFL9Fd6CHp2e%2FKw0x4bKz0N9lGk; xscdb_auth=8106rAyhKpQL49eMs%2FyhLBf3C6ClZ%2B2idSk4bExJwbQr%2BHSZrVKgqPOttHVr%2B6KLPg3DtWpTMUI4ttqNNVpukUj6ElM; cdbphpchina_onlineusernum=3721"; $snoopy->fetch("http://bbs.phpchina.com/forum-17-1.html"); $n=ereg_replace("href="","href="http://bbs.phpchina.com/",$snoopy->results ); echo ereg_replace("src="","src="http://bbs.phpchina.com/",$n); ?> ?这是模拟登陆PHPCHINA论坛的过程,首先要查看自己浏览器的信息:echo?var_dump($_SERVER);这句代码可以看到自己浏览器的信息,把?
$_SERVER['HTTP_USER_AGENT']后边的内容复制下来,粘在$snoopy->agent的地方,然后就是要查看自己的
COOKIE了,用自己在论坛的账号登陆论坛后,在浏览器地址栏里输入
javascript:document.write(document.cookie),回车,就可以看到自己的cookie信息,复制粘贴
到$snoopy->rawheaders["COOKIE"]=的后边。(我的cookie信息为了安全起见已经删除了一段内容)


然后再注意:


# $n=ereg_replace("href="","href="http://bbs.phpchina.com/",$snoopy->results );?


# echo ereg_replace("src="","src="http://bbs.phpchina.com/",$n);


这两句代码,因为采集到的内容所有的HTML源码地址都是相对链接,所以要替换成绝对链接,这样就可以引用论坛的图片和css样式了。转载:http://zzdboy1616.blog.163.com/blog/static/430670762009213111712876/?

?

热点排行