Toapi - 让任何一个网站提供API.

658 阅读1分钟
原文链接: github.com

Build Python Version License

Make existing web sites available with APIs. You can have your own APIs of your web. You can create your owen APIs from other's web. And Then, you can do something interesting with those APIs.

Feature

  • Convert static html to api.
  • Easy to use.

Installaton

  • pip install toapi
  • pip install git+https://github.com/gaojiuli/toapi/

Usage

from pprint import pprint

from toapi import XPath, Item, Api

api = Api('https://news.ycombinator.com/')

class Post(Item):
    url = XPath('//a[@class="storylink"][1]/@href')
    title = XPath('//a[@class="storylink"][1]/text()')

    class Meta:
        source = XPath('//tr[@class="athing"]')
        route = '/'

api.register(Post)

pprint(api.parse('/'))

api.serve()

Then, You get your api server. Powered by flask.

Contribute

  • Open issue.
  • Pull Request.

License

Apache-2.0