在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:gaojiuli/toapi开源软件地址:https://github.com/gaojiuli/toapi开源编程语言:Python 100.0%开源软件介绍:ToapiOverviewToapi give you the ability to make every web site provides APIs.
Features
Get StartedInstallation
Usagecreate 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 then open your browser and visit 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"
}
]
} ContributingWrite code and test code and pull request. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论