irfan-dahir/skraypar

此包已被废弃,不再维护。未建议替代包。

具有模式解析的爬虫

dev-master 2018-06-24 04:00 UTC

This package is not auto-updated.

Last update: 2020-01-23 10:16:05 UTC


README

作为(但不仅限于)Jikan API 的核心解析功能(作为独立的抽象类)进行开发。

进行中

安装

  1. 此库使用 Composer,请先安装。
  2. composer require irfan-dahir/skraypar

使用

<?php
require 'vendor/autoload.php';

class Parser extends \Skraypar\Skraypar {

	public function loadRules() { // Abstract function
		$this->addRule(
			'anime_url', // used as a hash key
			'~<meta property="og:url" content="(.*?)">~', // Pattern to match
			function() { // Function to execute when matched

				/*
				* $this->matches // output of pattern match
				* $this->line // current line
				* $this->lineNo // current line no.
				* $this->file // All lines in an array
				*/

				var_dump($this->matches);
			}
		);

		// Add more Rules here
	}
}

$parser = new Parser;
$parser->setPath('http://myanimelist.net/anime/1');
$parser->loadFile();
$parser->loadRules();
$parser->parse();

输出

array (size=2)
  0 => string '<meta property="og:url" content="https://myanimelist.net/anime/1/Cowboy_Bebop">' (length=79)
  1 => string 'https://myanimelist.net/anime/1/Cowboy_Bebop' (length=44)

更多示例

依赖

捐赠

如果您觉得这个项目有用,请随意捐赠!

Donate