Download the PHP package icy8/web-spider without Composer

On this page you can find all versions of the php package icy8/web-spider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package web-spider

多进程web爬虫框架

基于链接挖掘策略的web爬虫框架,实现多进程采集和xpath选择器等基础功能。

软件架构

  1. guzzlehttp
  2. php>=7.2
  3. 多进程模型
  4. Redis

安装

  1. 在线安装

  2. 离线安装

    下载项目解压到目录vendor/icy8

    编辑composer.json

    安装

  3. VCS安装

    编辑composer.json

    安装

原理

  1. 链接挖掘

    • 框架本身是基于链接的,大致分为列表页和内容页链接。其中内容页链接最为重要,是数据的来源页。
    • “挖掘”理解为字面意思,从页面中收集链接,然后筛选我们需要的链接,将其写入链接池中,这是一个简单的筛选过程。
  2. 链接池

    • 内置有基于SplQueueRedis作为链接存储的容器。
    • 基于SplQueue的容器:这个原理很简单,就是利用PHP自带的SplQueue类来作为队列,存储合格的链接。他是基于单进程的,多进程不建议使用这个容器来运行框架。
    • 基于Redis的容器:利用的是列表的数据类型存储,因为Redis大部分都是原子操作,所以可以利用Redis做多进程的数据容器。
  3. 选择器
    • 数据的匹配是基于各种选择器的,目前设想的有xpath正则两种方案。
    • xpath:基于DOMXPath封装的选择器,xpath相关语法需自行在网上查阅。
    • regex:基于正则表达式的选择器,暂未实现。

说明

  1. 本身只提供数据匹配,产生的数据需要自行写入库。
  2. 多进程采集要使用Redis作为链接池容器,否则会造成页面的重复采集,如果不介意这个问题的话可以忽略这一条。
  3. 多进程不支持windows系统。
  4. 不建议同一个脚本同时重复执行。

用例

  1. 编辑脚本crawl.php

  2. 执行脚本

Xpath选择器

用例:

事件

  1. onLinkDigging:链接入栈前触发,如果返回的是false,那么会阻止这一次的链接入栈。

    参数 类型 说明
    $spider \icy8\WebSpider\Spider 当前框架的实例
    $link \icy8\WebSpider\entity\Link 准备入栈的链接实例
  2. onPageReady:页面请求成功后和匹配字段前触发,在这个事件中可以通过改变$page->response属性提前过滤一些不需要的内容。

    参数 类型 说明
    $page \icy8\WebSpider\entity\Page 请求的页面实例
  3. onContentPage:页面请求成功后和字段匹配完成后触发。

    参数 类型 说明
    $page \icy8\WebSpider\entity\Page 请求的页面实例
    $data Array|boolean 匹配得到的数据值,如果匹配失败会返回false
  4. onListPage:页面请求成功后触发

    参数 类型 说明
    $page \icy8\WebSpider\entity\Page 请求的页面实例
  5. onEntryPage:页面请求成功后触发

    参数 类型 说明
    $page \icy8\WebSpider\entity\Page 请求的页面实例
  6. onLinkRetry:页面请求失败后触发,如果返回的是false,那么会阻止这一次重试操作。

    参数 类型 说明
    $link \icy8\WebSpider\entity\Link 请求的页面实例

实体

目前内置的实体都是要求实现\icy8\WebSpider\entity\QueueEntity接口的,因为部分实体如\icy8\WebSpider\entity\Link需要入栈链接池的,需要一个接口标准。

  1. \icy8\WebSpider\entity\Page:网页内容

    属性 类型 说明
    $link \icy8\WebSpider\entity\Link 当前页的链接信息
    $response string 当前页面的html
    $context string 来源页的html,暂未实现
    $linkDigging boolean 是否在这个页面挖掘链接,默认true
  2. \icy8\WebSpider\entity\Link:链接信息

    属性 类型 说明
    $url string 链接的url
    $retryTimes int 重试的次数,默认0
    $depth int 当前连接的深度,暂未实现
    $method string 规定请求时的方式,暂未实现
    $proxy string 规定请求时的代理地址,暂未实现
    $type int 链接类型,取值Link::CONTENT_PAGELink::LIST_PAGELink::ENTRY_PAGE
    $referer string 来源页的url

选择器接口

如果你想自定义一个选择器,你需要实现接口\icy8\WebSpider\selectors\Selector。接口说明:


All versions of web-spider with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
icy8/process Version *
guzzlehttp/guzzle Version ~7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package icy8/web-spider contains the following files

Loading the files please wait ....