1 Star 0 Fork 44

LEGEND / spider-utils-for-php

forked from mz / spider-utils-for-php 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

spider

PHP simple http client/spider class/简单的 PHP 的网络库

特色:

  • 简单易用
  • HTTP 抓取和匹配
  • 自动识别 HTML/XML 等文档编码为 utf-8
  • 支持多 IP 出口设置
  • 支持各类代理

Installation

composer require zv/spider

basic


$spider = new \ZV\Spider('https://www.baidu.com/s?wd=爱情&pn=50&rn=50&tn=json', [
    //'User-Agent' => 'mobile',
]);

$spider->GET();
print_r($spider->getResponseCode());
print_r($spider->getResponseHeader());
print_r($spider->getBody());
print_r($spider->getUrl());
print_r($spider->getJson());

POST


use \ZV\Spider as spider;

$spider = new spider('http://127.0.0.1/post', [
]);

$spider->POST([
    'query' => 1,
    // upload
    'file1' => '@' . __FILE__,
    // upload file with MIME
    'file2' => '@' . __FILE__ . ';text/plain'
]);

print_r($spider->getBody());

string utils


use \ZV\Spider as spider;

// html2txt (has newline)
echo spider::html2txt('<h1>html2txt</h1>'), PHP_EOL,

// no html(without newline)
spider::noHtml('<h1>noHtml</h1>'), PHP_EOL,

// strip_tags
spider::strip_tags('<h1>strip_tags</h1>'), PHP_EOL,

// cut str
spider::cut('<h1>cut</h1>', '<h1>', '</h1>'), PHP_EOL,
    
// match with mask
spider::maskMatch('<h1>maskMatch</h1>', '<h1>(*)</h1>'), PHP_EOL,
    
// match with regexp
spider::regMatch('<h1>regMatch</h1>', '#<h1>([^>]*?)</h1>#is'), PHP_EOL,
    
// match with multi pattern
print_r(spider::match('<h1>MatchByMultiPattern</h1><h2>Description</h2>', [
    'title' => '#<h1>([^>]*?)</h1>#is',
    'desc'  => '<h2>(*)</h2>'
]), 1), PHP_EOL;
MIT License Copyright (c) 2020 mz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

简单、易用、灵活的网络类,spider/network for PHP , too simple . 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

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

搜索帮助