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信息了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM