提供基于HTML解析对外网站api样式的访问的包

安装数: 4,584

依赖项: 1

建议者: 0

安全: 0

星标: 311

关注者: 21

分支: 39

开放问题: 3

语言:HTML

1.3.7 2015-03-10 08:39 UTC

This package is auto-updated.

Last update: 2024-09-16 20:55:41 UTC


README

Build Status Latest Stable Version Total Downloads License Code Climate

SleepingOwl Apist 是一个小型库,它允许您以api样式访问任何网站,基于HTML解析。

概述

此包允许您编写类似以下的方法

class WikiApi extends Apist
{

	public function getBaseUrl()
	{
		return 'http://en.wikipedia.org';
	}

	public function index()
	{
		return $this->get('/wiki/Main_Page', [
			'welcome_message'  => Apist::filter('#mp-topbanner div:first')->text()->mb_substr(0, -1),
			'portals'          => Apist::filter('a[title^="Portal:"]')->each([
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return $this->getBaseUrl() . $href;
				}),
				'label' => Apist::current()->text()
			]),
			'languages'        => Apist::filter('#p-lang li a[title]')->each([
				'label' => Apist::current()->text(),
				'lang'  => Apist::current()->attr('title'),
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return 'http:' . $href;
				})
			]),
			'sister_projects'  => Apist::filter('#mp-sister b a')->each()->text(),
			'featured_article' => Apist::filter('#mp-tfa')->html()
		]);
	}
}

并获得以下结果

{
    "welcome_message": "Welcome to Wikipedia",
    "portals": [
        {
            "link": "http:\/\/en.wikipedia.org\/wiki\/Portal:Arts",
            "label": "Arts"
        },
        {
            "link": "http:\/\/en.wikipedia.org\/wiki\/Portal:Biography",
            "label": "Biography"
        },
        ...
    ],
    "languages": [
        {
            "label": "Simple English",
            "lang": "Simple English",
            "link": "http:\/\/simple.wikipedia.org\/wiki\/"
        },
        {
            "label": "العربية",
            "lang": "Arabic",
            "link": "http:\/\/ar.wikipedia.org\/wiki\/"
        },
        {
            "label": "Bahasa Indonesia",
            "lang": "Indonesian",
            "link": "http:\/\/id.wikipedia.org\/wiki\/"
        },
        ...
    ],
    "sister_projects": [
        "Commons",
        "MediaWiki",
        ...
    ],
    "featured_article": "<div style=\"float: left; margin: 0.5em 0.9em 0.4em 0em;\">...<\/div>"
}

安装

在您的 composer.json 中添加此包,并运行 composer update(或直接运行 composer require sleeping-owl/apist:1.x

	"sleeping-owl/apist": "1.*"

文档

文档可在 sleeping owl apist 找到。

示例

查看 示例

支持库

您可以通过 PayPal、Yandex money (410012943296949) 或 BTC: 13k36pym383rEmsBSLyWfT3TxCQMN2Lekd 进行捐赠。

版权和许可

Apist 由 Sleeping Owl 编写,并按照 MIT 许可证发布。有关详细信息,请参阅 LICENSE 文件。