zoukankan      html  css  js  c++  java
  • python安装feedparser

    去官网下载:https://pypi.python.org/pypi/feedparser/

    $ python setup.py install

    结果报错:

    from setuptools import setup
    ImportError: No module named setuptools

    缺少setuptools(python是2.7.2,feedparse版本是5.1.3)

     安装setuptools.

    然后打开cmd

    cd feedparser目录

    C:\feedparser\python setup.py install.

    安装完成。

    然后第一次尝试。
    将下列代码保存在test.py里面。
    import sys
    import feedparser
    #List of uples (label, property-tag, truncation)
    COMMON_CHANNEL_PROPERTIES = [
        ('Channel title:', 'title', None),
        ('Channel description:', 'description', 100),
        ('Channel URL:', 'link', None),
    ]
    COMMON_ITEM_PROPERTIES = [
        ('Item title:', 'title', None),
        ('Item description:', 'description', 100),
        ('Item URL:', 'link', None),
    ]
    INDENT = u' '*4
    def feedinfo(url, output=sys.stdout):
        """
        Read an RSS or Atom feed from the given URL and output a feed
        report with all the key data
        """
        feed_data = feedparser.parse(url)
        channel, items = feed_data.feed, feed_data.entries
        #Display core feed data
        for label, prop, trunc in COMMON_CHANNEL_PROPERTIES:
            value = channel[prop]
            if trunc:
                value = value[:trunc] + u'...'
            print >> output, label, value
        print >> output
        print >> output, "Feed items:"
        for item in items:
            for label, prop, trunc in COMMON_ITEM_PROPERTIES:
                value = item[prop]
                if trunc:
                    value = value[:trunc] + u'...'
                print >> output, INDENT, label, value
            print >> output, INDENT, u'---'
        return
    if __name__ == "__main__":
        url = sys.argv[1]
        feedinfo(url)
     
    然后执行    python test.py http://cn.engadget.com/rss.xml
    然后就看到了处理过的rss信息了。
  • 相关阅读:
    Java设计模式(学习整理)---工厂模式
    Java Swing 使用总结(转载)
    Java-生成验证码图片(自定义内容,尺寸,路径)
    二维码(带有图片)的生成
    J2se中的声音---AudioPlayer
    文件的读取和写入(指定路径)
    ASP.NET:使用Flurl制作可复用的分页组件
    ASP.NET:Forms身份验证和基于Role的权限验证
    ASP.NET:MVC模板化机制
    ASP.NET:MVC中文件上传与地址变化处理
  • 原文地址:https://www.cnblogs.com/youxin/p/3061824.html
Copyright © 2011-2022 走看看