定制 monkeyphp/php-spider 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

monkeyphp/php-spider

Composer 安装命令:

composer require monkeyphp/php-spider

包简介

A basic web spider written in PHP.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

I needed a really basic spider to crawl a site to warm the cache; this is the result.

Examples

Simple

The simplest way to use PhpSpider is to construct an instance and pass the root url of the site that you wish to crawl to the Spider::crawl method.

By design, PhpSpider will only crawl pages that

  • Return a content-type header of text\html
  • That are on the same domain as the supplied root
use PhpSpider\Spider\Spider;

$spider = new Spider();
$spider->crawl('https://www.example.com');

Advanced

If you need to override how PhpSpider works you can add event listeners to be notified, that can then affect how PhpSpider operates.

There are 5 events triggered by PhpSpider

  • Spider::SPIDER_CRAWL_PRE - Triggered before PhpSpider starts to crawl a site.
  • Spider::SPIDER_CRAWL_POST - Triggered one PhpSpider has finished it's crawl.
  • Spider::SPIDER_CRAWL_PAGE_PRE - Triggered just before a page is crawled
  • Spider::SPIDER_CRAWL_PAGE_POST - Triggered once a page is crawled
  • Spider::SPIDER_CRAWL_PAGE_ERROR - Trigged if an error occurs whilst crawling a page

You can find examples in the examples directory included in this repository.

    $ php ./examples/example_0.php
use PhpSpider\Spider\Spider;
use Zend\EventManager\Event;

$listener function ($event) {
    $uri = $event->getParam('uri');
    echo $uri;
};

$spider = new Spider();
$spider->getEventManager()->attach(Spider::SPIDER_CRAWL_PAGE_PRE, $listener, 1000);

$spider->crawl('https://www.example.com');

To Run Tests

$ vendor/bin/phpunit -c tests/phpunit.xml

统计信息

  • 总下载量: 76
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-09-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固