apist

Package to provide api-like access to foreign sites based on html parsing

  • 所有者: sleeping-owl/apist
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

SleepingOwl Apist

Build Status
Latest Stable Version
Total Downloads
License
Code Climate

SleepingOwl Apist is a small library which allows you to access any site in api-like style, based on html parsing.

Overview

This package allows you to write method like this:

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()
		]);
	}
}

and get the following result:

{
    "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>"
}

Installation

Require this package in your composer.json and run composer update (or run composer require sleeping-owl/apist:1.x directly):

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

Documentation

Documentation can be found at sleeping owl apist.

Examples

View examples.

Support Library

You can donate via PayPal, Yandex money (410012943296949) or in BTC: 13k36pym383rEmsBSLyWfT3TxCQMN2Lekd

Apist was written by Sleeping Owl and is released under the MIT License. See the LICENSE file for details.

主要指标

概览
名称与所有者sleeping-owl/apist
主编程语言HTML
编程语言PHP (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2014-10-22 13:08:52
推送于2022-11-27 01:21:43
最后一次提交2015-04-29 13:25:22
发布数11
最新版本名称1.3.7 (发布于 2015-03-10 12:39:59)
第一版名称1.0.0 (发布于 2014-10-22 16:21:10)
用户参与
星数310
关注者数20
派生数40
提交数35
已启用问题?
问题数8
打开的问题数3
拉请求数2
打开的拉请求数0
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?