main.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:kodi-addons 作者: leonardoxiao 项目源码 文件源码
def get_categories():
    """
    Get the list of match categories.
    Here you can insert some parsing code that retrieves
    the list of match categories (e.g. 'Movies', 'TV-shows', 'Documentaries' etc.)
    from some site or server.
    :return: list
    """
    req = urllib2.Request(URL, headers=HEADERS) 
    con = urllib2.urlopen( req )
    content = con.read()
    soup = BeautifulSoup(content, "html.parser")

    items = []
    main_menu_1 = soup.find("ul", {"id":"menu-main-menu-1"})
    for li in main_menu_1.find_all("li"):
        item = {}
        if li.text == "HOME":
            item['name'] = 'Latest Hightlights and Full Matches'
            item['url'] = li.find("a")['href']
            items.append(item)
        else:
            sub_menu = li.find("ul", class_="sub-menu")
            if sub_menu == None:
                # We will skip the rest (live football, humor etc) for now
                continue
            else:
                for sub_item in sub_menu.find_all("li"):
                    item = {}
                    item['name'] = sub_item.text
                    item['url'] = sub_item.find("a")['href']
                    items.append(item)

    return items
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号