gaojiuli / toapi
- вторник, 5 декабря 2017 г. в 03:14:25
A library letting any web site provide APIs.
A library letting any web site provide APIs.
pip install toapi
pip install git+https://github.com/gaojiuli/toapi/
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)
print(api.parse('/'))
api.serve()
Phantomjs
is required. Run phantomjs -v
to check.sudo apt install phantomjs
to install.brew install phantomjs
to install.from toapi import XPath, Item, Api
api = Api('https://news.ycombinator.com/', with_ajax=True) # This meas use selenium to load the page source.
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)
print(api.parse('/'))
api.serve(ip='0.0.0.0',port='5000')
Visit: http://127.0.0.1:5000/
Then, You get your api server. Powered by flask.
Apache-2.0