Exemple #1
0
def main():
    samples = [
        '{}/samples/appledaily.html'.format(pkgdir),
        'https://tw.news.appledaily.com/local/realtime/20181025/1453825',
    ]

    logging.info('-' * 80)
    for path in samples:
        ns = NewsSoup(path, mobile=False)
        logging.info('路徑: {}'.format(path))
        logging.info('頻道: {}'.format(ns.channel))
        logging.info('標題: {}'.format(ns.title()))
        logging.info('日期: {}'.format(ns.date().isoformat()))
        logging.info('記者: {}'.format(ns.author()))
        logging.info('內文:')
        logging.info(ns.contents())
        logging.info('有效內容率: {:.2f}%'.format(ns.effective_text_rate() * 100))
        logging.info('-' * 80)
Exemple #2
0
def soup(path):
    """
    soup(path)
    """

    print('-' * 75)
    nsoup = NewsSoup(path, mobile=False)
    print('路徑: {}'.format(path))
    print('頻道: {}'.format(nsoup.channel))
    print('標題: {}'.format(nsoup.title()))
    ndt = nsoup.date()
    if ndt is not None:
        print('日期: {}'.format(ndt.strftime('%Y-%m-%d %H:%M:%S')))
    print('記者: {}'.format(nsoup.author()))
    print('內文:')
    print(nsoup.contents())
    print('有效內容率: {:.2f}%'.format(nsoup.effective_text_rate() * 100))
    print('-' * 75)