elliotgao2 / toapi

Every web site provides APIs.

Home Page:https://gaojiuli.github.io/toapi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple site routing problems.

elliotgao2 opened this issue · comments

The example:

from toapi import XPath, Item, Api

api = Api()


class Movie(Item):
    __base_url__ = 'http://www.dy2018.com'

    url = XPath('//b//a[@class="ulink"]/@href')
    title = XPath('//b//a[@class="ulink"]/text()')

    class Meta:
        source = XPath('//table[@class="tbspan"]')
        route = '/'


class Post(Item):
    __base_url__ = 'https://news.ycombinator.com/'

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

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

api.register(Movie)
api.register(Post)

api.serve()

When I visite http://127.0.0.1:5000/, it excepted to result in:

{
    post:[],
    movie:[]
}

When I visit http://127.0.0.1:5000/www.dy2018.com/, it excepted to result in:

{
    movie:[]
}

When I visit http://127.0.0.1:5000/news.ycombinator.com/, it excepted to result in:

{
    post:[]
}