Archive for the ‘snoopy’ tag
snoopy https 问题的解决
今天在使用snoopy进行https的post请求,开始无法正常使用,有两个问题,因为https使用curl命令所以要安装并设置对。
var $curl_path = “/usr/local/bin/curl”; 这里设置对你的路径。
由于https默认都是443,snoopy似乎没有进行处理。
解决办法在所有case “https”:下面增加
$this->port = 443;
使用Snoopy进行网页抓取
目前做了几个抓取都使用到了Snoopy。使用Snoopy可以快速实现一些抓取要做的工作。
1.fetch 抓取网页内容
2.submit 实现post操作
3.fetchlinks 获取网页中的所有连接地址
所有结果在属性results中,
如取得网页内容
require(’Snoopy.class.php’);
$snoopy = new Snoopy();
$snoopy->fetch(’http://www.coderhome.net/’);
$html = $snoopy->results;
echo $html ;
其它的大家自己看代码吧。
代码下载地址http://coderhome.net/ophtml/d597.html
共享我的获取网页基本内容的函数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // 输入url将获得网页的charset,title,description function parseSite($url) { global $snoopy; $snoopy->results = NULL; $snoopy->fetch($url); $html = $snoopy->results; //charset preg_match('/text\/html\;\s*charset\=([^>\"\']+)[\"\']?\s*\/?>/isx',$html,$match); $charset = strtolower($match[1]); //title preg_match('/<title>([^<>]*)<\/title>/isx',$html,$match); $title = $match[1]; $charset=='' && $charset='utf-8'; if ($charset!='' && $charset!='utf-8') { $title = iconv($charset,'utf-8',$title); } //description preg_match('/meta\sname\=[\'\"]?description[\'\"]?\scontent=[\'\"]?([^\'\"<>]+)[\'\"]?\s*\/?>/isx',$html,$match); $description = $match[1]; if ($charset!='' && $charset!='utf-8') { $description = iconv($charset,'utf-8',$description); } return array('url' => $url,'charset' => $charset,'title' => $title,'description' => $description,); } |

