Need help with toapi?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

gaojiuli
3.1K Stars 228 Forks Other 459 Commits 8 Opened issues

Description

Every web site provides APIs.

Services available

!
?

Need anything else?

Contributors list

# 22,812
bittorr...
Jupyter...
python3
Markdow...
172 commits
# 8,077
Python
HTML
Tensorf...
uvloop
78 commits
# 89,858
Python
HTML
Flask
spider
36 commits
# 228,317
HTML
Flask
spider
Linux
2 commits
# 120,184
Django
C
C++
instagr...
1 commit
# 48,264
Swift
Objecti...
Flask
sdwebim...
1 commit
# 185,407
confere...
HTML
CSS
Shell
1 commit
# 15,272
ruby-on...
Flask
Markdow...
chromiu...
1 commit

Toapi

Build Coverage Python Version License

Toapi

Overview

Toapi give you the ability to make every web site provides APIs.

Version v2.0.0, Completely rewrote.

More elegant. More pythonic

Features

  • Automatic converting HTML web site to API service.
  • Automatic caching every page of source site.
  • Automatic caching every request.
  • Support merging multiple web sites into one API service.

Get Started

Installation

$ pip install toapi
$ toapi -v
toapi, version 2.0.0

Usage

create

app.py
and copy the code:
from flask import request
from htmlparsing import Attr, Text
from toapi import Api, Item

api = Api()

@api.site('https://news.ycombinator.com') @api.list('.athing') @api.route('/posts?page={page}', '/news?p={page}') @api.route('/posts', '/news?p=1') class Post(Item): url = Attr('.storylink', 'href') title = Text('.storylink')

@api.site('https://news.ycombinator.com') @api.route('/posts?page={page}', '/news?p={page}') @api.route('/posts', '/news?p=1') class Page(Item): next_page = Attr('.morelink', 'href')

def clean_next_page(self, value):
    return api.convert_string('/' + value, '/news?p={page}', request.host_url.strip('/') + '/posts?page={page}')

api.run(debug=True, host='0.0.0.0', port=5000)

run

python app.py

then open your browser and visit

http://127.0.0.1:5000/posts?page=1

you will get the result like:

{
  "Page": {
    "next_page": "http://127.0.0.1:5000/posts?page=2"
  }, 
  "Post": [
    {
      "title": "Mathematicians Crack the Cursed Curve", 
      "url": "https://www.quantamagazine.org/mathematicians-crack-the-cursed-curve-20171207/"
    }, 
    {
      "title": "Stuffing a Tesla Drivetrain into a 1981 Honda Accord", 
      "url": "https://jalopnik.com/this-glorious-madman-stuffed-a-p85-tesla-drivetrain-int-1823461909"
    }
  ]
}

Todo

  1. Visualization. Create toapi project in a web page by drag and drop.

Contributing

Write code and test code and pull request.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.