0 Star 0 Fork 44

qidouhai / spider-utils-for-php

forked from mz / spider-utils-for-php 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

spider-utils-for-php:

##原则:

简单、易用、灵活、任性任性任性就是任性!

##特色:

  • php 界内最简单易用的 http-utils,自动识别支持 curl、socket、file_get_contents 三种方式。
  • http 请求支持 gzip,加速请求,节约请求成本。
  • 跟踪 301、302 跳转(可设置最大跳转数量)。
  • 支持统一转码为 utf-8,不再需要关心页面是否是 gbk、big5、utf8 等编码。
  • 字符串支持通配符、正则表达式、DOM表达式三种方式匹配。
  • url支持匹配后自动相对路径转绝对路径。
  • ToBe Continue.

##什么?转换相对路径到绝对路径

	// $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);

##What?发送http GET请求?

    // 所有的 http 请求都会自动识别并统一转码成 utf-8
    $result =  spider::GET('http://www.baidu.com/');

##What?发送http POST请求?

    $post = "wd=".urlencode("你的网址"); 
    // 数组也一样
    // $post = array("wd" => urlencode("你的网址"));
    $result = spider::POST('http://www.baidu.com/s?', $post);

##What?POST File?

    $post = array("wd" => "http://", "file" => "@c:/1.txt");
    $result = spider::POST('http://www.baidu.com/s?', $post);

##What?要带 UserAgent 和 Cookie?

	// 一切 headers 都可以传入
	$headers = array(
		'Cookie' => 'uid=1; my_name_is=mzphp',
		'UserAgent' => 'userAgentForIphone',
		'Referer' => 'http://baidu.com/',
		//设置外网 ip
		'ip' => '127.0.0.1',
		//设置代理
		'proxy' => array(
			'type' => 'HTTP', //HTTP or SOCKET
			'host' => 'ip:port',
			'auth' => 'BASIC:user:pass',//BASIC or NTLM
		),
	);
    $post = array("wd" => "http://", "test" => "123");
    $result = spider::POST('http://www.baidu.com/s?', $post, $headers);

##What?这些操作如何漂亮的“在一起”?

	// 首先你需要一个女朋友
	$key = "魔爪小说阅读器";
	$url = 'http://www.sogou.com/web?query='.urlencode($key).'&ie=utf8';
	$html = spider::GET($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']);
	}

##更多?

好吧,你可以参考一下 mzphp2 项目中的 start_example 里的index_control,on_spider 方法:

http://git.oschina.net/mz/mzphp2/blob/master/start_example/control/index_control.class.php

空文件

简介

a small php spider utils from MzPhp2 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/qihai/spider-utils-for-php.git
git@gitee.com:qihai/spider-utils-for-php.git
qihai
spider-utils-for-php
spider-utils-for-php
master

搜索帮助

14c37bed 8189591 565d56ea 8189591