# Path: crawler/gather/items.py
# class ChannelItem(Item):
#     office_id = Field()
#     short = Field()
#     name = Field()
#     image = Field()
#     url = Field()
# 
# class RoomItem(Item):
#     office_id = Field()
#     name = Field()
#     image = Field()
#     url = Field()
#     online = Field()
#     host = Field()
#     channel = Field()
#     followers = Field()
#     description = Field()
#     announcement = Field()
#     start_time = Field()


from scrapy import Spider, Request
from ..items import ChannelItem, RoomItem
import json
    name = 'bilibili'
    allowed_domains = ['bilibili.com']
    start_urls = [
        'http://live.bilibili.com/area/live'
    ]
    custom_settings = {
        'SITE': {
            'code': 'bilibili',
            'name': '哔哩哔哩',
            'description': '哔哩哔哩-关注ACG直播互动平台',
            'url': 'http://live.bilibili.com',
            'image': 'http://static.hdslb.com/live-static/common/images/logo/logo-150-cyan.png',
            'show_seq': 3
        }
    }

    def parse(self, response):
        panel_class = ['live-top-nav-panel', 'live-top-hover-panel']
        panel_xpath = ['contains(@class, "{}")'.format(pclass) for pclass in panel_class]
        room_query_list = []
        for a_element in response.xpath('//div[{}]/a'.format(' and '.join(panel_xpath)))[1:-2]:
            div_element = a_element.xpath('div[@class="nav-item"]')[0]
            url = a_element.xpath('@href').extract_first()
            if '/pages/area/' in url:
                i_class = div_element.xpath('i/@class').extract_first().split(' ')
                short = i_class[-1]
                url = self.custom_settings['SITE']['url'] + '/' + short
            else:
                short = url[url.rfind('/') + 1:]
            name = div_element.xpath('text()').extract_first()

# Path: crawler/gather/items.py
# class ChannelItem(Item):
#     office_id = Field()
#     short = Field()
#     name = Field()
#     image = Field()
#     url = Field()
# 
# class RoomItem(Item):
#     office_id = Field()
#     name = Field()
#     image = Field()
#     url = Field()
#     online = Field()
#     host = Field()
#     channel = Field()
#     followers = Field()
#     description = Field()
#     announcement = Field()
#     start_time = Field()


# Path: crawler/gather/spiders/bilibili.py
from scrapy import Spider, Request
from ..items import ChannelItem, RoomItem
import json

    name = 'bilibili'
    allowed_domains = ['bilibili.com']
    start_urls = [
        'http://live.bilibili.com/area/live'
    ]
    custom_settings = {
        'SITE': {
            'code': 'bilibili',
            'name': '哔哩哔哩',
            'description': '哔哩哔哩-关注ACG直播互动平台',
            'url': 'http://live.bilibili.com',
            'image': 'http://static.hdslb.com/live-static/common/images/logo/logo-150-cyan.png',
            'show_seq': 3
        }
    }

    def parse(self, response):
        panel_class = ['live-top-nav-panel', 'live-top-hover-panel']
        panel_xpath = ['contains(@class, "{}")'.format(pclass) for pclass in panel_class]
        room_query_list = []
        for a_element in response.xpath('//div[{}]/a'.format(' and '.join(panel_xpath)))[1:-2]:
            div_element = a_element.xpath('div[@class="nav-item"]')[0]
            url = a_element.xpath('@href').extract_first()
            if '/pages/area/' in url:
                i_class = div_element.xpath('i/@class').extract_first().split(' ')
                short = i_class[-1]
                url = self.custom_settings['SITE']['url'] + '/' + short
            else:
                short = url[url.rfind('/') + 1:]
            name = div_element.xpath('text()').extract_first()

            yield ChannelItem({'short': short, 'name': name, 'url': response.urljoin(url)})