spider-utils-for-php 介绍
spider-utils-for-PHP:
原则:
简单、易用、灵活、任性任性任性就是任性!
特色:
-
PHP 界内最简单易用的 http-utils,自动识别支持 curl、socket、file_get_contents 三种方式。
-
http 请求支持 gzip,加速请求,节约请求成本。
-
ToBe Continue.
[](http://git.oschina.net/mz/spider-utils-for-php#什么-
// $result = http://baidu.com/bac/index.html $result = spider::abs_url('http://baidu.com/abc/', '../bac/index.html');
什么?html2txt?
// $result = 123 $result = spider::html2txt('<p><a href="">1</a>23<p>');
什么?字符串截取?
// $result = 23abcde $result = spider::cut_str('123abcdef', '1', 'f');
什么?通配符匹配?
// $result = abc $result = spider::mask_match('123abc123', '123(*)123'); // $result = abc $result = spider::mask_match('abc123', '(*)123'); // $result = 123 $result = spider::mask_match('123abcabc', '(*)abc'); // $result = 123abc $result = spider::mask_match('123abcdef', '(*)abc', true);
[](http://git.oschina.net/mz/spider-utils-for-php#what-发送http-
get请求-)What?发送http GET请求?
// 自动转码 utf-8, $result = spider::fetch_url('http://www.baidu.com/');
[](http://git.oschina.net/mz/spider-utils-for-php#what-发送http-
post请求-)What?发送http POST请求?
$post = "wd=".urlencode("你的网址"); // 数组也一样 // $post = array("wd" => urlencode("你的网址")); $result = spider::fetch_url('http://www.baidu.com/s?',$post);
What?POST
File?
$post = array("wd" => "http://", "file" => "@c:/1.txt"); $result = spider::fetch_url('http://www.baidu.com/s?',$post);
[](http://git.oschina.net/mz/spider-utils-for-php#what-要带-useragent-和-
cookie-)What?要带 UserAgent 和 Cookie?
// 一切 headers 都可以传入 $headers = array( 'Cookie' => 'uid=1; my_name_is=mzPHP', 'UserAgent' => 'userAgentForIphone', 'Referer' => 'http://baidu.com/', ); $result = spider::fetch_url('http://www.baidu.com/s?', $post, $headers);
What?这些操作如何漂亮的“在一起”?
// 首先你需要一个女朋友 $key = "魔爪小说阅读器"; $url = 'http://www.sogou.com/web?query='.urlencode($key).'&ie=utf8'; $html = spider::fetch_url($url, '', array('Referer'=>'http://www.sogou.com/')); // 对你的女朋友进行分析 $keywordlist = spider::match($html, array('list'=>array( 'cut' => '相关搜索</caption>(*)</tr></table>', 'pattern' => '#id="sogou_\d+_\d+">(?<key>[^>]*?)</a>#is', ))); // $newarr = array(); foreach($keywordlist['list'] as $key=>$val){ $newarr[$val['key']] = array('key'=>$val['key']); }
More?
好吧,你可以参考一下 mzphp2 项目中的 start_example
里的index_control,on_spider 方法:
http://git.oschina.net/mz/mzphp2/blob/master/start_example/control/index_control.class.php
spider-utils-for-php 官网
http://git.oschina.net/mz/spider-utils-for-php
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。