zoukankan      html  css  js  c++  java
  • Python 模块feedparser安装使用

    RSS(简易信息聚合)

    简易信息聚合(也叫聚合内容)是一种RSS基于XML标准,在互联网上被广泛采用的内容包装和投递协议。RSS(Really Simple Syndication)是一种描述和同步网站的内容格式,是使用最广泛的XML应用。RSS搭建了信息迅速传播的一个技术平台,使得每个人都成为潜在的信息提供者。

    安装

    $ pip install feedparser
    

    feedparser 使我们轻松实现从任何RSS或者Atom订阅源得到标题、链接和文章的条目。

    具体测试

    import feedparser
    
    def test(url='http://blog.csdn.net/together_cz/article'):
        print('url:%s' % one_url)
        page_dict = feedparser.parse(url)
        ''' 解析得到的是一个字典 '''
        #print page_dict
        ''' 
        输出字典中的键值有哪些,一共有10中如下:
        ['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
        '''
        print page_dict.keys()
        print '#####################################################################'
        print '访问页面链接 href:'
        print page_dict['href']
        print '返回headers:'
        print page_dict['headers']
        print 'ersion信息为:'
        print page_dict['version']
        print '状态码为:'
        print page_dict['status']
        fd = page_dict.get('feed','')
        for key in fd.keys():
            print key 
        print '语言类型为:'
        print page_dict['feed']['html']['lang']
        print 'meta信息为:'
        print page_dict['feed']['meta']['content']
        print page_dict['feed']['meta']['name']
        print '#####################################################################'
    
    if __name__ == '__main__':
        url_list=['http://www.baidu.com',
                  'http://www.jd.com',
                  'http://www.vmall.com',
                  'http://www.taobao.com']
        for one_url in url_list:
            try:
                test(one_url)
            except:
                print '????????????????????????????????????????????????????????????'
    

    输出

    url:http://www.baidu.com
    ['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
    #####################################################################
    访问页面链接 href:
    http://www.baidu.com
    返回headers:
    {'content-length': '2701', 'content-type': 'text/html', 'content-encoding': 'gzip'}
    ersion信息为:
    
    状态码为:
    200
    meta
    summary
    语言类型为:
    ????????????????????????????????????????????????????????????
    url:http://www.jd.com
    ['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
    #####################################################################
    访问页面链接 href:
    https://www.jd.com/
    返回headers:
    {'content-length': '28099', 'via': 'BJ-Y-NX-105(HIT), http/1.1 CD-CT-1-JCS-42 ( [cRs f ])', 'ser': '13.215', 'content-encoding': 'gzip', 'age': '24', 'expires': 'Wed, 12 Sep 2018 14:23:27 GMT', 'vary': 'Accept-Encoding', 'server': 'JDWS/2.0', 'connection': 'close', 'strict-transport-security': 'max-age=3600', 'cache-control': 'max-age=30', 'date': 'Wed, 12 Sep 2018 14:23:45 GMT', 'content-type': 'text/html; charset=utf-8'}
    ersion信息为:
    
    状态码为:
    302
    html
    meta
    links
    script
    语言类型为:
    zh-CN
    meta信息为:
    webkit
    renderer
    #####################################################################
    url:http://www.vmall.com
    ['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'namespaces', 'entries', 'bozo_exception']
    #####################################################################
    访问页面链接 href:
    http://www.vmall.com
    返回headers:
    {'content-length': '781', 'connection': 'Keep-Alive', 'content-encoding': 'gzip'}
    ersion信息为:
    
    状态码为:
    200
    语言类型为:
    ????????????????????????????????????????????????????????????
    url:http://www.taobao.com
    ['feed', 'status', 'version', 'encoding', 'bozo', 'headers', 'href', 'etag', 'namespaces', 'entries', 'bozo_exception']
    #####################################################################
    访问页面链接 href:
    https://www.taobao.com/
    返回headers:
    {'x-swift-savetime': 'Wed, 12 Sep 2018 14:19:11 GMT', 'x-swift-cachetime': '300', 'x-cache': 'HIT TCP_MEM_HIT dirn:6:607364846 mlen:-1', 'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'vary': 'Accept-Encoding, Ali-Detector-Type', 'age': '274', 'strict-transport-security': 'max-age=31536000', 'eagleid': 'b68cf51715367622259114055e', 'server': 'Tengine', 'cache-control': 'max-age=60, s-maxage=300', 'connection': 'close', 'via': 'cache5.l2wt97[80,304-0,C], cache13.l2wt97[66,0], cache9.cn172[0,200-0,H], cache9.cn172[1,0]', 'etag': 'W/"2a36-165c95cc45b"', 'set-cookie': 'thw=cn; Path=/; Domain=.taobao.com; Expires=Thu, 12-Sep-19 14:23:45 GMT;', 'date': 'Wed, 12 Sep 2018 14:23:45 GMT', 'content-md5': 's6hP5DCqrrp9rS7Tz3jT+w==', 'content-type': 'text/html; charset=utf-8', 'timing-allow-origin': '*', 'x-snapshot-age': '2'}
    ersion信息为:
    
    状态码为:
    302
    links
    meta
    summary
    html
    link
    base
    语言类型为:
    zh-CN
    meta信息为:
    淘宝,掏宝,网上购物,C2C,在线交易,交易市场,网上交易,交易市场,网上买,网上卖,购物网站,团购,网上贸易,安全购物,电子商务,放心买,供应,买卖信息,网店,一口价,拍卖,网上开店,网络购物,打折,免费开店,网购,频道,店铺
    keyword
    #####################################################################
  • 相关阅读:
    无线网络安全标准是什么?漏洞是怎样产生的
    揭秘英特尔处理器如何启动?
    数据包级网络遥测和网络安全推送分析
    自动化与网络工程之间的关系
    ElementUI中的el-table中实现动态添加一行、删除一行、清空所有行
    ElementUI中的el-table实现多选框不勾选的提示
    Nodejs中的fs模块的使用
    ElementUI中的el-table怎样实现多选与单选
    MyBatis中针对if-test的参数为指定值的xml写法
    SqlServer中怎样从Excel中导入数据
  • 原文地址:https://www.cnblogs.com/vercont/p/10210343.html
Copyright © 2011-2022 走看看